Hi I have created a ftp cmd script that would copy the text files from local source to ftp folder destination. copying was succesful. but i want it to be more complex that after successfull copying, copy to another local folder (will serve as backup copy of text files, increment file name by 1 when exists) then it would delete the copied text files from the source.
My script goes like:
#ftp -i -s:"%~f0"&GOTO:EOF
open [172.16.xx.xx]
oracle
mypassword
cd /ftp_destination/
mput D:/local_source_folder
quit
I know it is to much to ask and it is a bit complex, but helping a newbie would be a great help. Thanks for advance help.
#ftp -i -s:"%~f0"&GOTO:EOF
open [172.16.xx.xx]
oracle
mypassword
cd /ftp_destination/
mput D:/local_source_folder
!del /q D:/local_source_folder
quit
! is the shell command for FTP, and anything after it will be executed in a "dos" shell.
Alternitively, you can just do !ENTER and FTP will open a "dos" shell for you to type in. EXIT will return you to ftp. Like this:
#ftp -i -s:"%~f0"&GOTO:EOF
open [172.16.xx.xx]
oracle
mypassword
cd /ftp_destination/
mput D:/local_source_folder
!
del /q D:/local_source_folder
exit
quit
Related
I am connected to a Unix server and I am trying to, via FTP, delete the directory dir with several files in it. If I use
ftp> delete dir/*
I get
550 Wildcard is ambiguous.
When I use
ftp> prompt off
Interactive mode off.
ftp> mdelete dir/*
I still get
550 Wildcard is ambiguous.
When I try
ftp> glob
Globbing on.
ftp> mdelete dir
I'm prompted for every file.
How can I easily delete/empty-and-delete a directory without getting prompted for every file?
I got it to work in two steps, on a server with restricted access, no SFTP, only FTP through commandline.
Like this :
mdelete folder_name/*
rmdir folder_name
If you've hidden files or folders on your server (for example .folder), you have to set the lftp list-options to "-a".
So this worked for me:
$ lftp -u user,pass server
> set ftp:list-options -a
> cd /folder/to/be/empty/
/folder/to/be/empty/> glob -a rm -r *
Use lftp to log into your server, this supports the rm -r command.
lftp user, password server
then:
rm -r directory
the -r stands for "recursive".
info:
http://en.wikipedia.org/wiki/Lftp
http://en.wikipedia.org/wiki/Rm_%28Unix%29#Options
$ ftp -i ...
will turn off prompting on mdel, which is what you want. It can't be done inside ftp.
rmdir directoryName
this directory must be in the current directory however.
cheatsheet: http://www.cs.colostate.edu/helpdocs/ftp.html
I'm using Filezilla, and it deletes folders recursively. I believe the ftp does not have a command that recursively deletes folders.
Ive been using a .bat script to download only pdfs from an FTP server.
Up until now its been working perfectly using the mget *pdf function.
I recently moved the script and have it running from a Windows 2012 Server.
And now when script gets to the mget function, it lists the files that would normally transfer except with a ? after each instance, it then fails to actually download them to the lcd.
#ftp -v -n -i -s:C:\Users\LMCT\Desktop\Serversidesage\download-1.txt
This is the FTP function being called.
open xx.xxx.xx.xxx
user xxxxxxxxxxx
=xxxxxxxxxxxx
cd orders
lcd "C:\Users\LMCT\Desktop\Magento-downloaded-orders"
binary
prompt
mget *pdf
mdelete *pdf
quit
And this is the downloading script.
Does anyone know why this might be happening?
Thanks in advance.
Kind Regards, Lewis.
By Default Interactive Prompting is ON. When you used the -I option to launch the FTP command it is turning Prompting off. In your script you are then turning it back on with the PROMPT command which then throws off your MGET command.
So if the PROMPT command is in your FTP script:
open ftp.domain.com
user ftpuser
password
prompt
quit
It is easy test to see what is going on.
C:\BatchFiles\ftp>ftp -v -i -n -s:"script.txt" |find "Interactive"
Interactive mode On .
C:\BatchFiles\ftp>ftp -v -n -s:"script.txt" |find "Interactive"
Interactive mode Off .
I'm on windows 8.1 and using ftp from the cmd console (run as administrator).
If I enter:
ftp -v -i -A thispc
Note: "thispc" is mapped in the hosts file to my local ip address
If I then enter:
mput *.*
all the files in my current folder get pushed to my ftp server.
However, if I try to do this from a .bat file, it does not work.
The .bat file:
#echo off
ftp -v -i -A thispc -s:send_file.txt
The contents of send_file.txt:
mput *.*
quit
I get the ftp help text instead when I run it via this .bat file with the following note:
mget and mput commands take y/n/q for yes/no/quit
The -i in the ftp call is supposed to disable that.
Does anyone know how I can get this to work.
OK - figured it out.
Quite simply:
ftp -v -i -A -s:send_file.bat thispc
instead of:
ftp -v -i -A thispc -s:send_file.txt
The error messages from ftp are not very useful :-)
Try
prompt
mput *.*
quit
In you input file.
I want to ftp file to my remote server and then move those files into another directory in the remote server
The ftp happens correctly but the movement is throwing an error like
550 RNFR command failed.
Can you please help?
My script is
#!/bin/sh
echo "Enter the version of the xml (eg:- v17.25)"
read version
HOST_FIRST='un01'
HOST_LAST='01'
USER='someuser'
PASSWD='somepassword'
HOST="$HOST_FIRST$FILE$HOST_LAST"
ftp -n $HOST <<-END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd /tmp
put myfile.xml
rename myfile.xml /tmp/test_ftp
quit
END_SCRIPT
exit 0
You have put myfile.xml to the tmp dir, why not just
edit
Change your script from
rename myfile.xml /tmp/test_ftp
TO
rename myfile.xml test_ftp
You have already put the file in the /tmp directory, which you have already done a cd /tmp .
That should work.
You can't specify a path in an ftp rename command and expect it to be moved as well.
And sorry, not what you want to here, but there is no move command in ftp. It is that way for security.
IHTH.
I have a text file on one computer that I want to send to a folder on a ftp site.
Can someone please show me a batch file code that will login to the FTP site with the username and password, and copy the text file.
Thanks for your help.
If you mean batch as in Windows batch, you can do that with the following script tst.cmd:
#ftp -n -stst.ftp myTargetMachine.com
(replacing myTargetMachine.com with the name of your actual FTP server) and the following FTP command file tst.ftp:
user myUser myPassword
dir
bye
Obviously, you should replace the myUser and myPassword with your actual username and password, and also dir command with whatever you really want to do, such as:
put localfile.txt /fullpath/remotefile.txt
If you're talking about a UNIX-like environment, the script would be:
#!/bin/bash
ftp -n myTargetMachine.com <<EOF
user myUser myPassword
dir
bye
EOF
Same deal with the FTP server name, user ID and password, of course.
And, in response to your comment:
Yes, I am talking about from a Windows environment. So for arguments sake, let's say the text file is C:\textfile.txt and I need to copy it to the FTP site in the folder called BACKUPS.
You would use a script like the following transfer.cmd:
#setlocal enableextensions enabledelayedexpansion
#echo off
c:
cd \
ftp -n -stransfer.ftp myTargetMachine.com
endlocal
and transfer.ftp:
user myUser myPassword
put textfile.txt /backups/textfile.txt
bye
If you wanted the Windows version as a single file, you could use something like:
#echo off
echo user myUser myPassword>tst.ftp
echo dir>>tst.ftp
echo bye>>tst.ftp
ftp -n -s:tst.ftp myTargetMachine.com
del /q tst.ftp
which temporarily creates tst.ftp and then deletes it when it's finished.
Command:
ftp -n -sScriptName HostName
And in the Script:
[User_id]
[ftp_password]
ascii
put myfilehere.html /remotedir/remotename.txt
quit