How to specify destination path using mget command - ftp

I am trying to copy multiple files from Linux machine to Windows using mget. Files are getting downloaded, but I'm not able to specify the destination directory (Windows directory)

The mget does not allow you to explicitly specify target local directory.
It always downloads the files to the current local working directory.
Though, you can change the local working directory using lcd command:
ftp> lcd C:\path
Local directory now C:\path.
ftp> mget *.*

Related

How to avoid some folder to download ftp terminal?

Am logged ftp using terminal below command,
ftp hostname
username
password
cd ..
cd public_html
ls
prompt noprompt
lcd /var/xxx/mylocalpath
mget *
the above commands its working fine start download files ,But I want to ignore some folder for example my images folder having lot of size like 6Gb like that.Is it possible to avoid some folder when start download file in ftp terminal?

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)

How to write command in windows batch file to copy a zip file from an FTP path to a local folder in my computer

I want to copy a zip file from an FTP path to a local folder in my computer.
My client previously used coreftp.exe for that purpose. But now he ask us to use ftp.exe [default in windows machine, available at C:\Windows\System32\ftp.exe] for that purpose. The ftp is in the format :
ftp://username#ftpserver.address.com
And want to download it to d:\sample\docs folder on my machine.
I want that in a batch file so that I can schedule it through windows task manager.
So could you please help me to write that command on the batch file.
Thanks a lot in advance.
FTP.EXE is capable of executing script files. So you could just put this into your bat file:
#ECHO OFF
CD d:\sample\docs
FTP -v -i -s:C:\some\path\ftpscript.txt
And something like this into your ftpscript.txt:
open ftp://ftpserver.address.com
username
password
cd myfolder
get some_zip_file.zip
disconnect
bye
This will download some_zip_file.zip into the current directory (d:\sample\docs).

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)

Resources