Copy files from Ftp to local directory using batch file - batch-file

I try to copy a lot o file from my ftp = ftp://ftp.prodega.ch so:
I created a code.txt file with this text:
open ftp://ftp.prodega.ch
user
password
lcd /D "E:\f2\" //this is my local directory
cd Bilder1/ //this is ftp folder
mget *
pause
the I execute in cmd this row : ftp -s:code.txt but I meet with this error:
unknown host: ftp://ftp.prodega.ch
help me please

When connecting to a server via the built-in FTP client you have to skip ftp://!
So open ftp.prodega.ch will fix your issue.
However, you might still face another problem. The standard FTP client doesn't support passive mode which is required by most of the servers. If you are not able to modify the server, you won't be able to download the files. You should consider using a PowerShell script instead or use a different FTP client with command line support.

Related

FTP Glob won't work

I have a problem with ftp via command line.
This is how I run the ftp file:
ftp -i -s:backup.ftp
pause
And this is my ftp file:
open HOST
USER
PASS
mget *.json
disconnect
quit
I am getting an error: no such file or directory. However if I change the * by a specific filename, it will work. As you can see, I didn't turn globbing off.
Also, when I connect to another ftp server, globbing does work. It seems like this ftp server blocks globbing or something. Anyone an idea??

Batch Remote Copy

I am interested in creating a batch file (ran on my computer) that can copy files from a server location to a computer connected to my network.
Something like:
xcopy //SERVER/FILE CONNECTEDCOMPUTER
It would be fine if I had to run the batch from the server or something like that. I just want to be able to remotely send a file to a connected computer.
As long as you have access to the files (the files are on a share you can read from), XCOPY should work fine. If you map a share to a local drive letter, you have the normal syntax for XCOPY as if you copy locally.
Without a mapped drive, simply use something like this to copy from server to C:\ :
XCOPY \SERVERNAME\SHARENAME\FILEORDIRECTORIES C:\
I am not sure I understand your aversion for sharing if what you want to do is share files... but you could install an ssh server for Windows on the remote machine, such as this - Bitvise
Then all you need to do is use
winscp file remote:
or
pscp file remote:
if you go the putty route.
Or you could install the free Filezilla FTP Server on the remote machine and send your file via FTP.

Batch script to upload file using FTP to a particular folder in remote server

I am using this script to upload files using FTP. However, it is uploading to the root folder in the server.
Can any one tell me to upload the file to a particular path on remote server, say '/CurrentQA'?
Before this line:
ECHO binary >> %Commands%
Try adding this line:
ECHO cd /some/directory >> %Commands%
This should enter the desired directory in the remote server (I haven't tested it though).

FTP batch script is not exiting with error status

There is a ftp command in my batch script :
FTP -n -s:D:\scripts\Test\get.ftp
Where get.ftp contains all ftp commands including "mget abc*".
Issue here is when file(s) of names starting with abc* is not available, mget is not failing. Also, if any other ftp command fails also, the script is not exiting with error status 1. i.e. "FTP -n -s:D:\scripts\Test\get.ftp" exiting without issues.
Not able to make the batch script fail when there is no file to pick up.
Need suggestion if someone has faced similar issue.
-Krishna
The mget command works by obtaining a remote folder listing and parsing the list for the wildcard pattern that you provide. As long as the listing can be obtained successfully,
it is not considered an error if your pattern did not match any of the files on the list.
Your batch script can be setup to compare the local folder listing before and after invoking the ftp command to check if a file was downloaded. You can also use a scripted ftp solution like kermit or ftp script to be able to have more control on error reporting.

A batch file to download and delete files from a server

How can I write a MS dos ftp batch file to:
download files from the server to my local pc
remove these files from the server after download
Edit:
So far I have...
Batch file:
ftp.exe -s:ftp.txt
FTP.txt:
open domain.com
usernamehere
passwordhere
cd /httpdocs/store/files
need get, list and delete commands here??
quit
The ftp.exe program can take a sort of script file as input (that example uploads a file, but I guess to get the idea), so you should probably be able to create a script for the commands that you need to carry out, and then have a batch file launch ftp.exe with the appropriate input.
From one of my cuestions in other post.
user-name
user-password
lcd c:\localfolder-where-download
cd remote-folder
mget .
mdelete \\remote-folder\ .
quit
1 & 2 line , your credentials
3 - line local folder where the ftp can download the content
4- line - remote folder if needed
5- line - get al content to your local folder
6- line - delete all content from your remote folder
7- line quit!
you can download ncftpput/ncftpget. With ncftpget, there's option to remove remote files after downloading.

Resources