LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   lftp upload (http://www.linuxquestions.org/questions/linux-networking-3/lftp-upload-637376/)

sycamorex 04-23-2008 04:53 PM

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

rayfordj 04-23-2008 05:53 PM

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.

sycamorex 04-24-2008 01:14 PM

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)

rayfordj 04-24-2008 03:54 PM

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).

sycamorex 04-24-2008 04:02 PM

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:(

rayfordj 04-24-2008 04:35 PM

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

sycamorex 04-24-2008 04:50 PM

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?

sycamorex 04-24-2008 04:55 PM

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.

sycamorex 04-24-2008 05:00 PM

update:
I saw the errors above so I thought it failed, but it has actually uploaded the file.

thanks for your help
:)

rayfordj 04-24-2008 05:13 PM

Quote:

Originally Posted by sycamorex (Post 3131905)
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. :)

Linux_420 07-28-2012 08:10 PM

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

vikas027 05-25-2013 02:22 PM

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.


All times are GMT -5. The time now is 09:13 AM.