Upload files to SFTP server and delete or archive the source files afterwards - ftp

I can't figure out a way to automatically sync files with an SFTP server that will do the following.
Syncs files from local PC to the SFTP
After upload deletes the file on the local PC and keeps SFTP file or
After upload moves the file that has been uploaded to another file for review.
I've tried using Ftpbox but it doesn't have the options.
WinSCP but couldn't find a script that would work.
Remote-Sync but didn't have the options.

If just want to move local files to a remote folder, use the WinSCP put command with the -delete switch.
A full Windows batch file would be like:
winscp.net /log=upload.log /command ^
"open sftp://username:password#example.com/ -hostkey=""ssh-rsa 2048 xxxxxxxxxxx...=""" ^
"put -delete C:\local\path\* /remote/path/" ^
"exit"
Have WinSCP generate the open command or even a complete batch file for you.
If you want to move/archive the local files to another local folder after the upload, it is more complicated.
See the official WinSCP example Moving local files to different location after successful upload.

Related

How to run batch file after file download (from Linux to Windows) throught FTP in Windows

I am doing file copy from Linux to Windows share through FTP.
Once copy is done I am moving it to isilon storage which is shared on network path (manually).
Now I have created a batch file, which will do copy from FTP shared path to network path.
So how can I start batch file after FTP download? How can I automate it completely?
from Linux
ftp -n ip
user "user" "pwd"
put app.tar.gz
Once it is done i want to move it network shared path
Just use the copy command in a batch file, after the ftp.exe finishes:
ftp.exe -s:download.txt
copy c:\dowloadtarget\myfile.txt \\server\share\target\myfile.txt
You can run the copy even from the FTP script (the download.txt), if you need it for some reason. Use the ! (escape to shell) command.
get /remote/path/myfile.txt c:\dowloadtarget\myfile.txt
! copy c:\dowloadtarget\myfile.txt \\server\share\target\myfile.txt
But why don't you download the file directly to the shared folder?
get /remote/path/myfile.txt \\server\share\target\myfile.txt

FTP 'rename' command to move remote files matching wildcard

I'm writing a *.bat file (Windows) in which I use FTP commands to get remote files back on a local machine. The remote directory includes a archive subdirectory in which I want to move the files once they are downloaded on the local machine.
My script in the *.bat file:
ftp -v -i -s:GET_FILES_FTP.txt
My script in GET_FILES_FTP.txt:
open example.com
username
password
lcd S:\
lcd repository/files
mget *.txt
rename *.txt archive/
disconnect
bye
Note that hostname, username and password are not those I use for real!
The TXT files are downloaded properly on the local machine.
The problem is that rename *.txt archive/ is not interpreted and the files do not move to the archive file. I the command window, I get an error message:
directory not found.
I can't find extra information better than this doc.
Any idea on how to move the files?
The rename command of the Windows ftp.exe does not support wildcards.
You would have to dynamically generate a script file based on a list of downloaded files with a separate rename command for each file.
Or use a different command-line FTP client that supports wildcards when renaming/moving.
For example with WinSCP scripting the batch file would be like:
winscp.com /log=winscp.log /command ^
"open ftp://username:password#example.com" ^
"lcd S:\" ^
"lcd repository\files" ^
"get *.txt" ^
"mv *.txt archive/" ^
"exit"
For details see:
mv command
Converting Windows FTP script to WinSCP FTP script
(I'm the author of WinSCP)

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.

Retrieve zip file from a predefined ftp link using bat or cmd file

I have a pre-defined ftp link with a zip file on the other end that I want to save to a directory on my cloud server (running Windows Server 2008). Once the zip file has been saved to a specified directory, lets say "c:\MyZipFiles\ZipFile-1.zip" for example, I want to unzip the file so that all files contained within the zip file are accessible within the same directory. I'm currently doing this manually and I want to automate this process by creating a .bat or .cmd file that will perform these steps for me.
Once the zip file is unzipped, I have a task in the Task Scheduler of Windows Server Manager ready to use the unzipped files for other things.
The pre-defined link looks something like this:
ftp://idx.realtor.com/idx_download/files.zip
I would greatly appreciate anyone who can help me with this...
Batch file
ftp -s:ftp_cmds.txt host-name-goes-here
unzip local-file.zip
exit
ftp_cmds.txt
username-goes-here
password-goes-here
cd remote-directory-goes-here
get files.zip local-file-name-goes-here.zip
quit
This the batch file uses "unzip" to unzip the archive you can find it here: http://gnuwin32.sourceforge.net/packages/unzip.htm
Either put the binaries in the same directory or put them somewhere else and set your windows PATH
I used my own ftp to test most of this. Your ftp was offline for me, so it might take some tweaking but this should put you in the right direction.

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