Connect to FTP via Shell Script issue - bash

While I am able to log in fine manually through the command line, for some reason my log in fails when I try to programmatically log in my Unix Shell script. I am using the same exact script which is successful for another FTP server and I know the values I’m passing are correct. Could this be a configuration issue on the FTP server side?
I get the error: 530 User cannot log in. Login failed.
Here is the code I'm using:
ftp -inv $FTPSERVER << EOF
user $USERNM $PASS
lcd $DLPATH
binary
prompt
mget *.txt
bye
EOF

Related

How to convert Windows FTP script to WinSCP?

I need to use WinSCP in my legacy vb6 code. I always used my script like this:
open ftp.myserver.com
myusername
mypassword
passive on
cd myfolder\
ascii
put C:\temp\test.xml test.xml
close
quit
Similar script (with little change) always worked for sslftp, psftp, etc.
Now I need to create script to make this WinSCP work but it keeps throwing "host not found error". I'm not even trying the script. I'm trying it on the command window.
winscp> open ftp.myserver.com
Searching for host...
Network error: Connection timed out.
same ftp works on regular command line ftp:
ftp> open ftp.myserver.com
Connected to myserver.
220 Gene6 FTP Server v3.10.0
User (...): myuser
331 Password required for myuser
Password:
230 User manager logged in.
How do I run WinSCP? The documentation doesn't show any such example.
WinSCP defaults to the SFTP protocol on the port 22. If you want to use the FTP, you need to specify that explicitly.
Also username and password come in session URL as part of the open command, not on separate lines. The passive mode is specified using the -passive=on switch.
open ftp://myusername:mypassword#ftp.myserver.com -passive=on
The ascii mode is specified using the -transfer=ascii switch of the put command (though the separate ascii command is also understood for compatibility):
put -transfer=ascii C:\temp\test.xml test.xml
It's the exit, not the quit.
See the complete guide for converting Windows FTP script to WinSCP.
You should also read the guide to automating file transfers to FTP server.

shell script to check ftp and sftp communication

First I have to say you that I'm a newbie, but I wanna learn!
I need a script which suppose to check the ftp and sftp communication. This is for 26 ftp and sftp.
Script has to execute just 1 times and script suppose to login to ftp and sftp servers using username with password, easy from an extern list.
If ftp works also it has to send an mail and even if it is fail also it suppose to send the mail. Or just a print on screen with status : alive or not alive should be ok.
I am starting with the below script:
I found something like :
"You can use your script with a regular user, creating the file .netrc in the user's homedir (~/.netrc), with the following contents:
Code:
machine 192.1.1.1
login usename
password user-passwd"
...
ftp -v -n <<EOF > ${LOG_FTP} 2>&1
open ${IP_ADDRESS_SERVER}
user ${FTPUSER} ${FTPPASS}
...
EOF
I need now to understand how I can send the email to my email adres or just print on screen the results.
Please can you suggest me the right way or help me write the script.
It would be great help for me.
Thanks in advance for all your help!
Nico
you can use sendmail for sending emails to your email id. IF you're working on bash, then pre-pend this line to your script:
#!/bin/bash
Then do this on terminal:
chmod +x <scriptname> #setting executable permission for script
./<scriptname> #executing the script

pass password to sftp in a bash script

I would like to automate a bash script, that connects to server using sftp and does a file transfer. I have the password for this, and initially I tried for this
sftp $acc#$host << EOF
<passwd_here>
cd $dir
get $file
quit
EOF
but it still prompted for password, and I had to enter it manually at the prompt.
After searching SO, I found this post which had a solution with expect, which I tried and I got the following error:
Script:
sftp -b cmdfile.txt $acc#$host
expect "Password:"
send "<passwd>\n";
interact
Error:
Permission denied (publickey,keyboard-interactive).
cmdfile.txt
cd $dir
get $file
quit
Please let me know, How to connect using the password in a bash script?
Please try the below steps
lftp -u $user,$pass sftp://$host << --EOF--
cd $directory
put $srcfile
quit
--EOF--
With scp/sftp you should use key-based authentication. Public key from the user you want to authenticate copy into ~/.ssh/authorized_keys file on the server, into home directory of user on which you want log on. Storing password in clear text on client side is not a good practice, you know :) That way you "workaround" problem of reading password from the prompt too.
Yes key-based auth is the way to go.
Check here for some direction.

bash script to sftp files with a password from remote directories to local folders

How to write a bash script using sftp command to download files?
I can use the following command to login to the remote machine, however I need to type in the password manually.
bash-3.2$ sftp -o "Port 22022" mike#s-edm-ssh.local.files.stack.com
mike#s-edm-ssh.local.files.stack.com's password:
Connected to s-edm-ssh.local.files.stack.com.
sftp>
How to do the sftp without the password prompt?
If I like to download aaa.txt file at /remote/mike/files to my local directory /local/mike/downloaded, how to build a script to do all of these work?
Since sftp runs over SSH, you can place your public key on the remote server.
If for some reason you can't place your key on the server, then you can write an Expect script to send your password when the prompt appears. See this example.

Batch script connect to ftp sever?

I am trying to connect to my ftp server by running a batch script. I can log into it fine by typing the following:
ftp home.ptd.net
USERNAME
PASSWORD
cd Public
put FILENAME.txt
bye
But if I put this into a script in this order, it connects to the server, but still asks for a username. Can anyone point me in the right direction on how to make it login? Thanks.
please see the following msdn article:
ftp reference from msdn
i think you need to place the commands in a text file and pass it to the ftp command with the -s parameter

Resources