-1

Here is the script I tried. Could someone help in fixing the bug in the script.?

FTPCommands.txt

open $hostname
user $username 
$password
latest_file=$(ls  File_Name* | tail -1)
binary
dir=F:/home/user/myFolder
cd $dir
put $latest_file
quit

Running the script as FTPTest.bat

ftp -i -s FTPCommands.txt > FTPLog.txt

While I'm calling directory in script , 550 error code is seen in the logs.

Jeremiah
  • 1
  • 1
  • What "script" is that? How do you run it? Show us the log! – Martin Prikryl May 10 '17 at 16:45
  • open $hostname connected...... user $username $password 220 authenticating dir=F:/home/user/nyfolders latest_file=$(ls *File_Name* | tail -1) Invalid command binary cd $dir 550 Invalid sytempath put $latest_file Invalid command quit – Jeremiah May 10 '17 at 18:10
  • Edit the question and add the error there - with proper formatting – Todor Minakov May 10 '17 at 18:35

1 Answers1

1

You're mixing FTP commands with shell ones in your file. The forth line for example, sets a value (in bash syntax) based on the output of piped commands, one of which is tail - none of this is possible in the FTP protocol. Plus, judging by the .bat extension, and the path in the dir variable, you're running this in Windows.

Prepare the variable outside the FTP command list file (in the bat file), and have it substituted. And don't forget FTP is not a shell session, you can't issue any typical *nix commands in it.

Todor Minakov
  • 19,097
  • 3
  • 55
  • 60