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 .
Related
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 am using ftp in the command line (terminal) to transfer multiple data files from a remote server to my local computer. There are multiple files (~40) in the directory and I would like to transfer them all without having to answer yes in the prompt for each file. I tried mget * but this only transferred the first file and then a prompt popped up for the second file.
Issue a prompt command first to turn interactive prompting off.
Alternatively, if you have control over the way the ftp command is called, use the command line option, as suggested by #reg-edit:
ftp [-i | --no-prompt] [OPTIONS] [HOST [PORT]]
As an alternative to issuing a prompt command ahead of your other commands, you may invoke ftp with the -i switch.
When you already started ftp you can issue the prompt command to toggle between getting prompted and not getting prompted. So this should do the trick:
> ftp <some server>
ftp> prompt
Interactive mode OFF .
ftp> mget *
I´d like to make Windows .cmd script file. One of its commands makes use of the ftp command. When I execute the batch script, the commmand prompt does not wait for the user to type his user/password, so the next commands are not properly executed. How can I make it to pause?
Thanks.
Edited:
My question was more related to the interactive use of the command (-i option) than the automatic login (-n option). I want to wait for the user to enter their credentials.
Also, I have seen that by typing the command:
ftp -n -i -s:myFtpCommands.txt 192.168.0.20
and that myFtpCommands.txt contains:
use myUser
mget *
bye
There is no need to type the password to get files. Where is the associated security problem?
You could ask the user for their details before hand, then build the command file based on their input.
#echo off
set /p un=Enter your FTP username:
set /p pw=Enter your FTP password:
echo open 192.168.0.20 >ftpscript.txt
echo %un% >>ftpscript.txt
echo %pw% >>ftpscript.txt
mget * >>ftpscript.txt
bye >>ftpscript.txt
ftp -i -s:ftpscript.txt
With regards to the auto login, this is a feature of FTP, it's an anonymous login, that is setup on FTP servers to allow this sort of access.
Whoever setup the FTP server would be able to control the accounts that are allowed to be used to access the server, and the permissions on the files that they don't want everyone to have access to.
I am using plink to execute the shell script on the remote MachineB. And shell script is there on the MachineA(Windows Box).
C:\PLINK>plink uname#MachineB -m test.sh
Using keyboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Your Kerberos password will expire in 73 days.
And that shell script generates the output in a text file(aa.txt) on MachineB and that gets stored in /export/home/uname/aa.txt
So my question is- Is there any way that I can copy the aa.txt file from MachineB to MachineA as soon the script has completed all its task using the ssh. Or we need to put all these things in Windows Batch file?
So Problem Statement is like this-
Execute the shell script on MachineB from MachineA.
Then wait for the shell script to complete its task, in my case it will write the output to a text file.
And after the shell script has completed all its task means it finished writing everything to a txt file, then copy that txt file to MachineA from MachineB
Any suggestions will be appreciated on how I can achieve the above scenario?
Update:-
So Suppose if this is the content in test.sh shell script file and also after adding pscp at the end of script, then it should be like this?
#!/bin/bash
export HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"
hive -S -e 'SELECT count(*) from testingtable2' > aa.txt
pscp uname#MachineB:/export/home/uname/aa.txt c:\documents\foo.txt
So I am executing a hive query in the above script and whose output is getting stored in aa.txt file and as soon as the query is completed and output is stored in aa.txt file, it will go to fourth line of pscp which will transfer aa.txt file to my local windows machine inside documents folder. Am I right? This will be the whole process?
And if the above process is right as far as I understood, then I can simply go to windows cmd prompt, and do like below and it will do the exact same process. Right?
C:\PLINK>plink uname#MachineB -m test.sh
Using keyboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Your Kerberos password will expire in 73 days.
Updated Again:-
So I need to create a bat file, and suppose this is the below test.bat file, so content should be like this in that test.bat file-
plink uname#MachineB -m test.sh
pscp uname#MachineB:/export/home/uname/aa.txt c:\documents\foo.txt
You can use scp to download the file after execution. If you setup winsshd on your windows machine and append a copy command in the test.sh file:
scp /export/home/uname/aa.txt user#windowsmachine.com:/homedir
The file will be transferred after completion.
Similarly, you can use a windows scp client like pscp on your windows machine, you can pull the file from the linux machine:
pscp uname#MachineB:/export/home/uname/aa.txt c:\documents\foo.txt
So on windows machine, have a batch script:
plink uname#MachineB -m test.sh
pscp uname#MachineB:/export/home/uname/aa.txt c:\documents\foo.txt
Just to add on to what has already been said, I am running something very similar and use the following format (from a batch script):
plink -ssh user# -pw password -m yourScript.sh
pscp -sftp -pw password user#IP-Address:/path/to/remote/file C:\path\to\local\save\directory
That second command is on one line, but it might not render like that on here. Of course, replace IP-Address, user, and password with the appropriate values for your login :-)
Hope that helps!
EDIT - Sorry, just realized this EXACT answer was already given. Kudos!
I am writing my first shell script ever and trying to figure out how to transform this command:
sftp -o IdentityFile=/home/test/test/id_dsa test#test.test.com < sftp_put.txt;
into an equivalent command where I connect to a ftp server. The key difference is that I will be logging into this server via a username and password not my ssh credentials. Note I am trying to upload two files.
Again any help would be more than appreciated!
You can use .netrc for this:
$ cat > .netrc
machine your.machine.ip.address
login your.login.name
^D
$ ftp your.machine.ip.address < ftp_cmds.txt
Which would prompt you for a password. If you're okay with it, you can save the password (clear text) in .netrc to skip this prompt. See man netrc for more details.
ftp -v -n <<EOF > ${LOG_FTP} 2>&1
open ${IP_ADDRESS_SERVER}
user ${FTPUSER} ${FTPPASS}
cd ${REMOTE_DIR}
put sftp_put.txt
EOF