1

I need to transfer a file from my linux server to a FTP server.

My shell script is :

    #! /bin/ksh

    HOST='my_ip'
    USER='userid'
    PASSWD='password'
    FILE='file.txt'
    DIREC='/eir_log'
    ftp -in $HOST << EOMYF 
    user $USER $PASSWD
    binary
    mkdir $DIREC 
    cd $DIREC
    pwd
    quit
    EOMYF

pretty simple code. but the problem is though I am logging in the FTP server fine, but its not allowing me to create a new directory in the FTP server. At first i thought some error with my script, but even individually if i run a mkdir in the ftp server its showing create directory failed. Can somebody let me know the possible error, or if any eror in my code that i am missing out on.The pwd is working fine though, which means there is no problem loging in the ftp site through script.

Thanks in advance for your help

dig_123
  • 2,240
  • 6
  • 35
  • 59
  • does your user have a $HOME on that server? put a `echo `cwd`` on the script after the login... – oz123 Sep 26 '12 at 09:03
  • All: I wanted to revisit this question after a long time again. Though my automated "ftp/sftp" is working fine now, i wanted to keep a sleep time between one expect and the next send in my expect program. Can this be done using the same linux sleep ? – dig_123 May 21 '15 at 13:23

4 Answers4

4

Have a look at expect

Something to get you started

#!/usr/bin/expect

set timeout 120
spawn ftp 192.168.0.210
expect "Name"
send "root\r"
expect "Password:"
send "pass\r"
expect "ftp> "
send "bye\r"
Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
1

Probably lftp ( ftp scripting client ) will be something you need ( look among your distro's packages ). Error creating directories is probably related to permissions of the dir inside which you try to create it.

http://lftp.yar.ru/desc.html

Piotr Wadas
  • 1,838
  • 1
  • 10
  • 13
0

Have you tried using SCP (Secure Copy)?

scp -r /dir/to/"file.txt" username@hostname

*if you're in the directory of the file/folder you wish to send then you don't need to define the complete filepath

Have a look at this article if you want to scp without having to enter your password. http://www.thegeekstuff.com/2008/06/perform-ssh-and-scp-without-entering-password-on-openssh/

Jones Agyemang
  • 1,230
  • 16
  • 15
0

If you are root or have admin privileges then you shouldn't need to sudo your way into making a directory. It will be best to run remote commands without sudo just in case a malicious code piggybacks your script

Jones Agyemang
  • 1,230
  • 16
  • 15