LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-23-2008, 04:53 PM   #1
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,406
Blog Entries: 1

Rep: Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951
lftp upload


I'm trying to automate uploading certain files to my network storage (ftp account). That's not a problem once I've run lftp, however, I want to write a script that would do it. For example, when I finish editing a file, I'd like to run a script, which will upload it to my network storege without specifying the username/password, etc.
the address is 192.168.1.102, and it uses port 1979

I found out that I could use:

Code:
lftp -f script
script:
Quote:
user remoteusername remoteuserpassword
cd ftp://192.168.1.102:1979:/data/notes/
lcd /home/xtd8865/notes/
put -a file
exit
also tried

Quote:
user remoteusername@192.168.1.102:1979 remotepassword
cd /data/notes/
lcd /home/xtd8865/notes/
put -a file
exit
however both give me errors

Quote:
cd: Access failed: 550 Requested action not taken. (/data/notes)
put: Access failed: 550 Requested action not taken. (myfile)
Quote:
cd: Not connected
put: Not connected
respectively


any hints

thanks
 
Old 04-23-2008, 05:53 PM   #2
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 475

Rep: Reputation: 73
i'll have to test some things to be more accurate so hopefully this will put you on the right path.

lftp honors settings in ~/.netrc
so you can define user/pass in there.
~/.netrc
Code:
machine <NAS> login <user> password <password>
(note: ~/.netrc needs -rw------- permissions [chmod 0600 ~/.netrc)

~/script.lftp
Code:
open <NAS>
cd /data/notes/
lcd /home/xtd8865/notes/
put -a file
quit
(if still having problems you could enable 'debug' in the lftp script so lftp is more verbose about its activities)

then test it
Code:
lftp -f ~/script.lftp
Hope this helps.

Last edited by rayfordj; 04-23-2008 at 05:55 PM. Reason: permissions for ~/.netrc
 
Old 04-24-2008, 01:14 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,406
Blog Entries: 1

Original Poster
Rep: Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951
Thanks for your reply. I still got errors.

~/.netrc

Code:
machine 192.168.1.102:1979 login sycamorex password blahblahblah
script.lftp

Code:
debug
open 192.168.1.102:1979
cd /data/notes/
lcd /home/xtd8865/notes/
put -a  sshX
quit

Code:
$ lftp -f script.lftp 
---- Resolving host address...
---- 3 addresses found
---- Connecting to 192.168.1.102 (192.168.1.102) port 1979
<--- 220 NET Disk FTP Server ready.
---> FEAT
<--- 530 Not logged in.
---> USER anonymous
<--- 230 User logged in, proceed.
---> FEAT
<--- 211- Extension supported:
<---  PASV
<---  SIZE
<--- 211 END
---> PWD
<--- 257 "/" is current directory.
---> CWD /data/notes
<--- 550 Requested action not taken.         
cd: Access failed: 550 Requested action not taken. (/data/notes)
---> PASV
<--- 227 Entering Passive Mode (192,168,1,102,210,139).
---- Connecting data socket to (192.168.1.102) port 53899
---- Data connection established
---> ALLO 397
<--- 500 Syntax error, command unrecognized.
---> STOR sshX
<--- 550 Requested action not taken.
---- Closing data socket
put: Access failed: 550 Requested action not taken. (sshX)
---> QUIT
---- Closing control socket
sshX is the file I'm trying to transfer.

Then I thought perhaps there's something wrong with the directories, so I removed them from the 'script.lftp'

Code:
debug
open 192.168.1.102:1979
# cd /data/notes/
# lcd /home/xtd8865/notes/
put -a  sshX
quit



Code:
$ lftp -f script.lftp
---- Resolving host address...
---- 3 addresses found
---- Connecting to 192.168.1.102 (192.168.1.102) port 1979
<--- 220 NET Disk FTP Server ready.
---> FEAT
<--- 530 Not logged in.
---> USER anonymous
<--- 230 User logged in, proceed.
---> FEAT
<--- 211- Extension supported:
<---  PASV
<---  SIZE
<--- 211 END
---> PWD
<--- 257 "/" is current directory.
---> PASV
<--- 227 Entering Passive Mode (192,168,1,102,210,149).
---- Connecting data socket to (192.168.1.102) port 53909
---- Data connection established
---> ALLO 397
<--- 500 Syntax error, command unrecognized.
---> STOR sshX
<--- 550 Requested action not taken.
---- Closing data socket
put: Access failed: 550 Requested action not taken. (sshX)
---> QUIT
---- Closing control socket
There shouldn't be any problems with permissions on the NAS. When I:
lftp sycamorex@192.168.1.102:1979
Once I'm in, that's where I'd like to put the file:
Code:
$ pwd
ftp://sycamorex@192.168.1.102:1979/data/notes
Code:
lftp sycamorex@192.168.1.102:/data/notes> put -a sshX
406 bytes transferred
As you can see I can upload without any problems.

any hints?

Edit: I don't think it matters but it's Fedora 9 beta, lftp has already been installed by default (or has been installed by me via yum)

Last edited by sycamorex; 04-24-2008 at 01:17 PM.
 
Old 04-24-2008, 03:54 PM   #4
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 475

Rep: Reputation: 73
did you set the permissions to 0600 for ~/.netrc
chmod 0600 ~/.netrc
if the permissions are not 0600 (if group or other have any permission bit set at all) then ~/.netrc is ignored for "security" reasons.

from the debug, it looks like lftp is attempting anonymous login (probably due to permission not being 0600 on ~/.netrc).
 
Old 04-24-2008, 04:02 PM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,406
Blog Entries: 1

Original Poster
Rep: Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951
yes, I did it

Code:
[xtd8865@fedlappy ~]$ ls -al | grep .netrc 
-rw-------  1 xtd8865 xtd8865      64 2008-04-24 19:46 .netrc
I also copied .netrc to .lftp/ (just in case) but still the same error
 
Old 04-24-2008, 04:35 PM   #6
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 475

Rep: Reputation: 73
i'll see what i can find and get back to you shortly.
i think it may have to do with the port specification...

Edit 1
try this in your script

/tmp/script.lftp
Code:
debug
open -u <user>,<pass> -p 1979 <nas>
cd /data/notes/
lcd /home/xtd8865/notes/
put -a  sshX
quit

Code:
lftp -f /tmp/script.lftp

Last edited by rayfordj; 04-24-2008 at 04:40 PM.
 
Old 04-24-2008, 04:50 PM   #7
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,406
Blog Entries: 1

Original Poster
Rep: Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951
I also added:
account mypassword
to .netrc, no effect though.

What's that bit, anyway:

Quote:
<--- 227 Entering Passive Mode (192,168,1,102,211,160).
---- Connecting data socket to (192.168.1.102) port 54176
211, 160?
the address is 192.168.1.102

port 54176?
what does it do with this port?

Last edited by sycamorex; 04-24-2008 at 04:55 PM.
 
Old 04-24-2008, 04:55 PM   #8
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,406
Blog Entries: 1

Original Poster
Rep: Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951
thanks, I just saw your reply
It's getting better

Code:
[xtd8865@fedlappy notes]$ lftp -f script.lftp 
---- Resolving host address...
---- 3 addresses found                            
---- Connecting to 192.168.1.102 (192.168.1.102) port 1979
<--- 220 NET Disk FTP Server ready.
---> FEAT
<--- 530 Not logged in.
---> AUTH TLS
<--- 500 Syntax error, command unrecognized.
---> USER sycamorex
<--- 331 User name okay, need password.
---> PASS blahblahblah
<--- 230 User logged in, proceed.
---> FEAT
<--- 211- Extension supported:
<---  PASV
<---  SIZE
<--- 211 END
---> PWD
<--- 257 "/" is current directory.
---> CWD /data/notes
<--- 250 Requested file action okay, completed.
---> PASV
<--- 227 Entering Passive Mode (192,168,1,102,211,190).
---- Connecting data socket to (192.168.1.102) port 54206
---- Data connection established
---> ALLO 397
<--- 500 Syntax error, command unrecognized.
---> STOR sshX
<--- 150 Opening BINARY mode data connection for sshX.
---- Closing data socket
<--- 226 Closing data connection.                 
---> QUIT
---- Closing control socket
now it logs in properly.
 
Old 04-24-2008, 05:00 PM   #9
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,406
Blog Entries: 1

Original Poster
Rep: Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951
update:
I saw the errors above so I thought it failed, but it has actually uploaded the file.

thanks for your help
 
Old 04-24-2008, 05:13 PM   #10
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 475

Rep: Reputation: 73
Quote:
Originally Posted by sycamorex View Post
I also added:
account mypassword
to .netrc, no effect though.

What's that bit, anyway:



211, 160?
the address is 192.168.1.102

port 54176?
what does it do with this port?
This is how passive port is negotiated to connect to.

(first number * 256) plus second number


211*256=54016
54016+160=54176

means, connect to my IP on 54176; i'll be waiting.
(short version)



Edit 1
Glad we finally got it worked out.

Last edited by rayfordj; 04-24-2008 at 05:15 PM.
 
Old 07-28-2012, 08:10 PM   #11
Linux_420
LQ Newbie
 
Registered: Dec 2011
Distribution: Fedora
Posts: 27

Rep: Reputation: Disabled
Lightbulb

maybe something like this: (I know it works)

Quote:
#
!/usr/bin/expect -f

# Usage: ./expect_test.sh <host> <username> <password>

set var1 [lindex $argv 0 ]
set var2 [lindex $argv 1]
set var3 [lindex $argv 2]
puts $var1
puts $var2
puts $var3
spawn lftp $var1
expect "*>"
send -- "connect $var1\r"
expect "*>"
send -- "login $var2\r"
expect "Password:"
send -- "$var3\r"
interact
 
Old 05-25-2013, 02:22 PM   #12
vikas027
Senior Member
 
Registered: May 2007
Distribution: RHEL, CentOS
Posts: 1,241

Rep: Reputation: 96
Lightbulb

Dear All,

Though this is a very old thread, still I am posting a probable solution to the issue(s) faced by OP in hope of helping others.

I had faced similar issues while using lftp for mput command.

I had created a VSFTPD server (CentOS 5.8 x86_64) with SSL/TLS and used "lftp" to check it. I was able to connect it, but when I tried to upload files, I got the below error.

Code:
mput: Access failed: 550 Permission denied. (install.log)
Strangely, when I used the below code in script it worked well.
Code:
# cat /tmp/abc.lftp 
set ftp:ssl-force true
set ftp:ssl-protect-data true
open -u test,redhat 192.168.1.10
ls
mkdir abc
mput install.log
ls
quit
#
I had wasted around 5 hours trying to get it right with lftp, but nothing worked.

Finally, I tried using windows FTPS clients like Filezilla and FTP Voyager. Filezilla also gave some issues, but everything was smooth with FTP Voyager. SSL connections and data transfer were clearly indicated in the logs and all seemed to be well.

Hope this helps someone.
 
  


Reply

Tags
lftp, script, upload


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
lftp mikeshn Linux - Software 11 07-20-2011 12:44 PM
FXP with lftp... thedp Linux - Software 0 07-01-2006 07:03 AM
Proftpd upload to a folder other than 'upload' fooboo Linux - Software 4 04-27-2006 07:51 PM
lftp HELP knappster Linux - Software 2 08-03-2004 10:34 AM
about lftp oskernel Linux - Software 1 10-29-2003 02:14 PM


All times are GMT -5. The time now is 08:06 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration