I can't succeed to upload a multiple files to some FTP by batch file I made.
Also, I want to upload all files from this local directory.
The code:
ftp -s:"C:\automation\fileup.bat" MYSERVER.COM
USERNAME
PASSWORD
ascii
cd "/public_html/reports/"
lcd "C:\automation\tests\HtmlReporter"
mput *
close
quit
The error:
C:\automation>ftp -s:"C:\automation\fileup.bat" MYSERVER.COM
Connected to server26.000webhost.com.
220---------- Welcome to Pure-FTPd [privsep] ----------
220-You are user number 12 of 500 allowed.
220-Local time is now 07:03. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
User (MYSERVER.COM:(none)):
331 User USERNAME OK. Password required
230-OK. Current restricted directory is /
230-109 files used (1%) - authorized: 10000 files
230 14084 Kbytes used (0%) - authorized: 1536000 Kb
ftp> ascii
200 TYPE is now ASCII
ftp> cd "/public_html/reports/"
250 OK. Current directory is /public_html/reports
ftp> lcd "C:\automation\tests\HtmlReporter"
Local directory now C:\automation\tests\HtmlReporter.
ftp> mput *
mput 000500de-0092-0095-00d9-00a100f000f7.json? close
mput 00090020-0041-007c-00db-00b9003c0085.json? quit
ftp>
The files I've trying to upload:
Use the prompt
command to turn off transfer confirmation prompts:
Toggles prompt mode on and off.
Without it, tje ftp
uses the following commands in the script (the close
and the quit
in your case) as answers. As they are not y
, the transfer is skipped.
Another option with the same effect is using the -i
switch on the ftp
command-line:
-i : Disables interactive prompting during multiple file transfers.
This should do it:
ftp -i -s:"C:\automation\fileup.bat" MYSERVER.COM
And in your script, end it like this:
mput *
bye
FTP command allows sending multiple files but if we want directories and sub-directories auto created and transferred then alternatively, we can use ncftp. Steps below:
- Download NcFTP Client 3.2.6 for Microsoft Windows if you're using Windows PC for transferring files to Linux Server via FTP
- Since, you're trying to send via batch file, we can use ncftpput command which is Internet file transfer program for scripts
- Create batch file (say, ncftpupload.bat) and provide as:
Syntax:
ncftpput -u username -p password -m -R SERVER_IP_ADDRESS /remote_directory local_directory\*
Example:
ncftpput -u ftpuser1 -p ftppass1 -m -R 192.168.1.10 /var/www C:\public_html\*
The switches used are:
-u: FTP username
-p: FTP password
-m: Attempt to make the remote destination directory before copying.
-R: Recursive mode; copy whole directory trees