SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    Brampton, Ontario
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unix Shell Script FTP issue

    Hey guys, I'm hoping someone can help me out here. I wrote a shell script to automate uploading a file to another server via FTP.

    I've tested doing this via ftp from the prompt and it works file. I've written the same thing in a shell script yet it doesn't work. The script is below:

    #!/bin/sh
    ftp -v -n host << EOF
    user xxxxx password
    cd /remotedirectory/xxxx/
    lcd /localdirectory/xxxx/
    put mySQLResults.txt
    bye
    EOF

    When I run this script from the command line, it returns:

    Connected to edxxxx.xxx.xxx.com (142.17x.xxx.xxx).
    220 FTP server ready.
    Remote system type is UNIX.
    Using binary mode to transfer files.
    331 Password required for xxxxx.
    230 User xxxxx logged in.
    250 CWD command successful.
    : No such file or directory
    remote: mySQLResults.txt
    : No such file or directory
    ?Invalid command
    ?Invalid command
    221 Goodbye.

    If I manually type the commands at the shell, it works fine, but when I run the script, it doesn't. Can anyone help me out with this one please?

    Thanks

  2. #2
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe the first comment in the following thread should help you
    http://www.neowin.net/forum/index.php?showtopic=419593

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    Brampton, Ontario
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cmuench View Post
    I believe the first comment in the following thread should help you
    http://www.neowin.net/forum/index.php?showtopic=419593

    Well thanks for the reply, but that wasn't helpful at all.

    I managed to resolve this, and the solution wasn't because of my code being incorrect, but rather because of where I wrote it. I wrote it in notepad, in windows, and then uploaded this to unix.

    The issue is that the heredoc interpretes newlines differently than windows does, so to resolve this, I just redid this in a new file using VI from the ssh prompt. Changed nothing, and viola!! it worked.

    So incase anyone ever have any problems with shell scripting, make sure you don't write your code in a windows editor and try to execute in Unix shell


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •