FTP script failing [duplicate] - batch-file

This question already has answers here:
How to ftp with a batch file?
(10 answers)
Closed 4 years ago.
I am trying to create a script which copies the contents of one directory to an FTP location but every example I have tried to work with has failed. I need this to target a folder within the FTP site can anyone point me in the right direction.
Thank you
Batch file is below.
#ftp -i -s:"%~f0"&GOTO:EOF
open 0.0.0.0
name#address.com
Pa55word
!:--- FTP commands below here ---
lcd c:\program files\system\location
cd storage
binary
mput "*.*"
disconnect
bye

Once FTP is open you are no longer at a command prompt. You are inside FTP. You need to use your batch file to write the ftp script,FTPInstructions.ftp in the following example. Then open ftp, telling it to run the script.
When you invoke the ftp.exe program to run the ftp script from the batch file you can redirect the ftp.exe console output to a log file and examine that log file for errors. You'll need to redirect both stdout and stderr. Something like this:
echo open 0.0.0.0>FTPInstructions.ftp
echo user UserName>>FTPInstructions.ftp
echo Password>>FTPInstructions.ftp
echo something>>FTPInstructions.ftp
echo something else>>FTPInstructions.ftp
.
.
echo bye>>FTPInstructions.ftp
ftp.exe -n -s:FTPInstructions.ftp>FTPSession.log 2>&1
You can then use FIND or FINDSTR in the batch file to locate any error messages output by ftp.exe in the FTPSession.log file.

Related

Uploading files to an FTP server via a batch file [duplicate]

This question already has answers here:
Batch file to upload all files in directory to FTP
(2 answers)
Closed 5 years ago.
I need to upload a set of .txt files to an FTP server using a .bat file. So far, I've managed to connect to the FTP server, including the correct directory that I need to put the file into and then disconnect. However, it isn't uploading the files.
In my .bat file, I've got this line to start the process
ftp -s:ftp.txt
Then, in ftp.txt, I've got
open my.ip.address
myUserName
myPassword
binary
cd myDir
cd myDir
put C:\MyFolder\*
quit
It goes to the correct directory when I run the batch file, the output being
OK. Current directory is /myDir/MyFolder
ftp> put C:\MyFolder*
Error opening local file C:\MyFolder..
ftp> quit
Goodbye. You uploaded and downloaded 0 kbytes.
Why is it erroring when trying to upload all files from C:\MyFolder\? Is there another way to upload all of the files from a folder?
put is used for a single file. To upload multiple files, use mput instead.
mput C:\MyFolder\*
You may also want to put a prompt on the line before the mput line so that you aren't prompted to press Y for each file in the folder.

Access denied while redirecting output from plink to local file

I am trying to redirect my plink command file output (That executes a script on UNIX server) to another file. But I am getting Access Denied issue while redirecting output.
Batch file:
cd "C:\Program Files\PuTTY"
plink -t w44gq8asd#USA7061UX02.wv.abcd.net -pw T#12Ts "PATH=/bin:/usr/bin:/usr/local/bin /opt/siebel/w44gq8asd/a.sh" > output.txt
cmd
Your working directory is in Program Files, where you do not have a write permissions, so it's only natural, that you are getting "Access denied".
You have to write the output file to a different folder:
plink ... > C:\path\where\you\can\write\to\output.txt
If you wanted to write to the path, where your batch file is, what about not changing the working directory in the first place:
"C:\Program Files\PuTTY\plink" ... > output.txt
(and remove the cd command)

copy files from ftp to local error [duplicate]

This question already has answers here:
I can't upload a multiple files to FTP by batch script
(3 answers)
Closed 4 years ago.
I try to copy a lot of files from my ftp server ftp://ftp.prodega.ch, so I created a file called code.txt with this text:
open ftp.prodega.ch
user
password
lcd E:\f2
cd Bilder1
get file1.jpg
bye
Then I execute the following command in the command prompt:
ftp -s:code.txt
The file file1.jpg is copying into local E:\f2 folder; I try to copy all files from the ftp folder Bilder1 using mget * instead of get file1.jpg but it doesn't work.
The first image is copied successfully, but the second image (using mget *) doesn't get copied and showed this result:
How would I be able to copy these files?
Try entering this command into your command prompt:
ftp -i -s:code.txt

Upload files using a batch file not sending ftp commands?

The command I am sending is:
ftp -s:ftp.txt
Here are the contents
open host.com
user
pass
lcd .
cd ./public_html/path/to/dumps
binary
mput "omega.txt2"
mput "wo.txt2"
When I run this, it logs in just fine but then stops. How can I make it run the mput commands also once it connects?
ftp displays a confirmation prompt to start uploading and waits for your input.
Use -i command line switch to disable prompting:
ftp -i -s:ftp.txt
Try to debug your script by connecting without it and then run each ftp command by typing in cmd:
ftp ftp.host.com
user
...
mput "wo.txt2"
This might help:
Ftp
Ftp subcommands

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