LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2012, 03:35 PM   #1
ali2011
Member
 
Registered: Nov 2011
Location: USA, CA
Distribution: Ubuntu+Fedora
Posts: 80

Rep: Reputation: Disabled
SSH and FTP


I don't understand why I'm getting different redirections "report.ftp" when I send the ftp command via ssh and when I do the ssh directly from the remote host!

With ssh I do the following:
Code:
echo ""; while read machine; do echo "We are testing $machine"; ssh -n -i ~/rsa_key myexper_test@$machine 'ftp 211.5.25.10 > report.ftp'; done < list
The file is transferred but the report.ftp only contained:
Code:
$ cat report.ftp
WARNING! 22955 bare linefeeds received in ASCII mode
File may not have transferred correctly.
When I log to the remote and do the ftp from there with the same command sent via ssh:
Code:
ftp 211.5.25.10 > report.ftp
I get the full report.ftp correctly:
Code:
$ cat report.ftp
Connected to 211.5.25.10 (211.5.25.10).
220 (vsFTPd 2.0.5)
331 Please specify the password.
230 Login successful.
cd ping/thr
250 Directory successfully changed.
get TEST.mp3
local: TEST.mp3 remote: TEST.mp3
227 Entering Passive Mode (211,5,25,10,99,198).
150 Opening BINARY mode data connection for TEST.mp3 (5492819 bytes).
WARNING! 22955 bare linefeeds received in ASCII mode
File may not have transferred correctly.
226 File send OK.
5492819 bytes received in 22.9 secs (239.37 Kbytes/sec)
quit
221 Goodbye.

Last edited by ali2011; 07-18-2012 at 04:45 PM.
 
Old 07-18-2012, 07:03 PM   #2
antegallya
Member
 
Registered: Jun 2008
Location: Belgium
Distribution: Debian
Posts: 109

Rep: Reputation: 42
Hello,

how do you pass your commands to the ftp session ?
 
Old 07-19-2012, 02:34 AM   #3
ali2011
Member
 
Registered: Nov 2011
Location: USA, CA
Distribution: Ubuntu+Fedora
Posts: 80

Original Poster
Rep: Reputation: Disabled
antegallya: the commands are as above. The first and second codes are the ftp command over ssh and the cat of its saved file on the remote host. The third and forth codes are the ftp command executed directly on the remote host and its saved file.
 
Old 07-19-2012, 07:11 AM   #4
antegallya
Member
 
Registered: Jun 2008
Location: Belgium
Distribution: Debian
Posts: 109

Rep: Reputation: 42
Yes, I understood what are the different ways you use to start the ftp session. But how are the ftp username, password, cd, get and quit issued ? Do you enter them manually ?
Did you already try removing the "-n" option of your ssh batch command ? You know it redirects stdin from /dev/null, right ?
Does your bash does any configuration specific things at login ? I mean configuration that may change the behavior of your ftp connection in your .bashrc or .bash_profile. As issuing an ssh command directly as you do does not open a login shell.
 
Old 07-19-2012, 10:06 AM   #5
ali2011
Member
 
Registered: Nov 2011
Location: USA, CA
Distribution: Ubuntu+Fedora
Posts: 80

Original Poster
Rep: Reputation: Disabled
Yes, the login info for ftp over the ssh are automated using .netrc file, and also with the direct ftp (i.e., the second one), the login info are automated using the same .netrc file. No specific bash configuration is implemented.

Last edited by ali2011; 07-19-2012 at 10:14 AM.
 
Old 07-19-2012, 10:24 AM   #6
ali2011
Member
 
Registered: Nov 2011
Location: USA, CA
Distribution: Ubuntu+Fedora
Posts: 80

Original Poster
Rep: Reputation: Disabled
The -n option is a necessary option to use ssh-ing in a while loop. I tried with for loop (i.e., no -n), and got the same result!
 
Old 07-19-2012, 10:28 AM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
the first thing i dont understand is if you got ssh installed why dont you use scp instead of ftp ?
 
Old 07-19-2012, 11:17 AM   #8
ali2011
Member
 
Registered: Nov 2011
Location: USA, CA
Distribution: Ubuntu+Fedora
Posts: 80

Original Poster
Rep: Reputation: Disabled
schneidz: On the testbed I'm working on, both ssh and scp are ONLY allowed between my private machine (i.e., not a node in the experiment). I have no permission to use ssh or scp between remote nodes.
 
Old 07-19-2012, 11:36 AM   #9
antegallya
Member
 
Registered: Jun 2008
Location: Belgium
Distribution: Debian
Posts: 109

Rep: Reputation: 42
Quote:
Originally Posted by schneidz View Post
the first thing i dont understand is if you got ssh installed why dont you use scp instead of ftp ?
I assume ali2011 wants each of its remote machines to retrieve some file from a central ftp server and get the result logged (on each machine again, independently). Scp is thus no option.

ali2011, I'm okay with all the login stuff. But I don't understand how you issue your "get" and "quit" commands to the ftp shell.

But anyway, that doesn't matter. Your problem is that there's an undocumented behavior of the ftp command : it checks if stdin is coming from a tty. If not, it goes into silent mode.
Adding -v for verbose should do the trick, but you won't have the prompt printed in your output file.
Another trick is using the "script" command to fake a tty like that :
Code:
ssh -n -i ~/rsa_key myexper_test@$machine "script -c 'ftp 211.5.25.10 &> report.ftp'"
Regards,
Antegallya

Last edited by antegallya; 07-19-2012 at 11:39 AM. Reason: Make the file redirection for stdin and stderr for the report
 
Old 07-19-2012, 12:38 PM   #10
ali2011
Member
 
Registered: Nov 2011
Location: USA, CA
Distribution: Ubuntu+Fedora
Posts: 80

Original Poster
Rep: Reputation: Disabled
antegallya, the get and quit command are issued from macro in the .netrc file.

Code:
machine IP-Address login user_name password user_pass
macdef init
cd test
get file.txt
quit
BTW, I did try the (ssh -n -i ~/rsa_key myexper_test@$machine "script -c 'ftp 211.5.25.10 &> report.ftp'"), and no file is printed with name report.ftp. While when I issued the (script -c 'ftp 211.5.25.10 &> report.ftp') without ssh-ing directly on the remote host the result is OK!

Last edited by ali2011; 07-19-2012 at 12:42 PM.
 
Old 07-20-2012, 10:17 AM   #11
antegallya
Member
 
Registered: Jun 2008
Location: Belgium
Distribution: Debian
Posts: 109

Rep: Reputation: 42
Hello,

I didn't knew about macdef, you taught me something here, thanks.
I hope it works with the verbose option because I've got no clue why it doesn't work with "script". I'm afraid we're encountering a "it works for me" situation here.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ftp over ssh tunnel; ftp refuses to work jakykong Linux - Networking 16 10-16-2011 07:34 AM
Access to one server via root/ssh/ftp on other only ftp anthonychallis Linux - Newbie 4 01-12-2010 02:23 PM
ftp within SSH DJOtaku Linux - Software 1 03-13-2005 08:34 PM
SSH and FTP quozt Linux - Networking 4 08-22-2003 07:10 AM
FTP and SSH Ikik Linux - Networking 10 08-20-2003 10:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration