Script Windows FTP move and rename file - windows

basically i have a 2 files on my company FTP, i need the users to be able to click a script to swap the 2 files when they want.
FTP tree look like this:
/file1.vxml
/swap/file1.vxml
And here i need to connect to my ftp (on Windows), and rename /file1.vxml to /file2.vxml before moving then move it to /swap/ (to not overwrite /swap/file1.vxml). Then doing the opposite on /swap/file2.vxml and move it to the root.
i already have the connection :
open host.myhost.com
user myusername
mypassword
cd /
bye
but the thing i'm lacking is how to move and rename properly files on the ftp.

Use "REN" to rename files in FTP.
ftp> REN FileA FileB
Renaming and moving are the same thing essentially in FTP, you can move a file to a different folder by renaming it.
ftp> REN Here ../There
You'll probably have to download the first file back to your local server to save a copy, then rename the second file, and copy the file you downloaded back up to the server afterwards. I don't know of any FTP servers that support copying files within themselves.

Related

Make WinSCP Better than NotePad++ Plugin FTP_Synchronize

Notepad++ FTP_Sync plugin works in this way:
It creates a cache directory (let's say cacheDir) and saves each FTP file like this:
cacheDir
- user#server.com
-- root
--- public_html
---- any_directory
----- any_file.*
- anotheruser#sameORotherserver.com
-- root
--- public_html
---- any_directory
----- any_file.*
- and so on...
Now if we open a file in WinSCP with Notepad++, it creates a temporary directory (something like scp45214) in Windows's temporary directory. If I open another file, it creates another new temporary directory (scpxxxx). So WinSCP doesn't maintain directory structure of FTP file under Window's temporary directory and also when I close WinSCP, it deletes all temporary (scpxxxx) directories...
Can we make WinSCP setting's work just like Notepad++ FTP_Sync plugin, so it can save and maintain directory structure of FTP file?
In WinSCP, go to the Storage page of Preferences dialog and check the option Append remote path to temporary path.
But this still won't prevent WinSCP from deleting local copies on exit.
Request for this is tracked here:
https://winscp.net/tracker/593
Alternatively, consider using the WinSCP feature Keep remote directory up to date:
With it, you can work on a local copy of the files and have the changes automatically mirrored on your server.

Automatically copy contents of FTP folder to local Windows folder without overwrite?

I need to copy all the files of an FTP folder to my local Windows folder, but without replacing the files that already exist. This would need to be a job/task that runs unattended every hour.
This is what the job would need to do:
1. Connect to FTP server.
2. In ftp, move to folder /var/MyFolder.
3. In local PC, move to c:\MyDestination.
4. Copy all files in /var/MyFolder that do not exist in c:\MyDestination.
5. Disconnect.
I had previously tried the following script using MGET * (that runs from a .bat), but it copies and overwrites everything. Which means that even if 1000 files were previously copied, it will copy them again.
open MyFtpServer.com
UserName
Password
lcd c:\MyDestination
cd /var/MyFolder
binary
mget *
Any help is appreciated.
Thanks.
Use wget for Windows.
If you want to include subdirectories (adjust the cut-dirs number according to the depth of your actual remote path):
cd /d C:\MyDestination
wget.exe --mirror -np -nH --cut-dirs=2 ftp://UserName:Password#MyFtpServer.com/var/MyFolder
If you don't want subdirectories:
cd /d C:\MyDestination
wget.exe -nc ftp://UserName:Password#MyFtpServer.com/var/MyFolder/*
The "magic" bit (for this second form) is the -nc option, which tells wget not to overwrite files that are already there locally. Do keep in mind that old files are also left alone, so if a file on your FTP server gets edited or updated, it won't get re-downloaded. If you want to also update files, use -N instead of -nc.
(Note that you can also type wget instead of wget.exe, I just included the extension to point out that these are Windows batch file commands)

In FTP, how do I copy a remote file to other directories

Using FTP commands I want to upload a large file once and then copy that file to many directories on the remote FTP server. All the copy commands seems to relate to copying from local to remote or the other way around.
Is there an FTP command to copy remote to remote?
are you trying to move the file? if yes, you can do it using rename command to move the file, as for copy i guess you still have to do the the get,send from local-remote way.
as for move command should be something like this
rename /oldpath/file2move.txt /newpath/file2move.txt
Basically just rename your file path that is infront of the file that you wish to move.
As far as I know, there is no such command available in FTP protocol. There are some extensions to SFTP protocol to do this (and, having SSH access, you can issue cp commands), but SFTP is not an FTP.

Loop over all files on FTP using batch command

Hi I want to LOOP through files on FTP and copy one by one. Every thing is fine with FTP connection and accessing folders.
My question is How can loop through all files on FTP. It looks like there is no "For" type of functionality available to access FTP files because each line is considered as complete command.
open MyServerName 21
MyUserName
MyPassword
lcd E:\LocalDirectory
cd /FTPDirectory/upload
I WANT TO LOOP THROGH ALL FILES AND COPY ONE BY ONE TO LOCAL DIRECTORY
disconnect
bye
Why i want to loop through all files in FTP is, I want to copy only those files which are not locked and available for copy.
Use a different FTP client: wget.
With the -m option (for --mirror), use the following in a script
cd mylocaldirectory
wget -m ftp://username:password#hostname/theremotedirectory

FTP Batch file moving remote files

I have an FTP batch file that uses DOS commands to pull down some files. After I'm done pulling the files down, I would like to move the files to an archive directory on the remote server. What FTP DOS commands do I use to accomplish this?
*I wasn't clear at first but this move has to take place on the remote server.
before you pull the files down, you can use the lcd (local cd) command to move to your archive directory and then pull them down directly there. you can then lcd back to your working directory.
otherwise you can perform the move in your bat after your ftp session is completed.
edit:
in the case that your archive server is remote, your best bet is to finish your ftp session and then perform the move in your .bat.
ftp has a rename command, that should move files remotely. I haven't tried it though

Resources