Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 937
  • Last Modified:

test script and upload file to ftp from Linux command line

I am being asked the following question on an job interview test.   My strength is in SQL which will comprise most of the duties.  I will be learning Linux on the job.  A few Linux questions were thrown into the mix on the test.

Any help here?

"You have written a script in a text editor on your Windows XP workstation, which is designed to run on your company’s Linux-based server. You need to upload it to that server via FTP or SCP, login via SSH, test that the script’s syntax is correct, and then execute that script. From the Windows & Linux command line, show the commands you would use to do this. You may specify instructions using whatever type of scripting language (Perl, Korn, Bash, etc…) you have experience with."
0
Delta7428
Asked:
Delta7428
  • 2
1 Solution
 
AlexPaceCommented:
Remember that Windows has different line endings than Unix so you'll need to convert the line endings or send it in ASCII mode over FTP which should do the line ending conversion automatically on the fly...  whereas binary mode just sends the file exactly as-is so you'd end up with Windows line endings on the Linux box which would need to be fixed...  Newer SFTP (SSH) servers support a text mode that can do line-ending conversions but both the client and server have to support it so you would want to check that or just plan on doing the conversion.
0
 
Delta7428Author Commented:
Can you give me example commands to do the ftp and test the script?

This is a research and learn part of the questionnaire as I am not expected to be proficient in this area.  I will credit this post for any code I use in a possible solution.
0
 
AlexPaceCommented:
I barely use the Windows command line FTP client anymore for the following reasons:
  1. It only supports Active Mode data channels so you need a special firewall configuration for any computer where you want to use it.
  2. Although you can script it, error handling is a hack, as is branching/conditional logic so you can only script the most simple operations... lucky for you the operation you have been asked to script is very simple!
  3. FTP.exe is not installed by default on newer versions of Windows so you have to go add it in the Control Panel for any computer where you want to use it.  I usually have administrator access and handy access to the Windows installation media and I still think this step is a pain in the rear.
  4. My employer provides a superior scriptable FTP client named Robo-FTP so I would use that program's syntax... here it is with no error handling, scheduling or automatic retry logic:
WORKINGDIR "c:\local\source\folder"
FTPLOGON "ftp.linuxmachine.com" /user=MyLogin /pw=MySecret 
FTPCD "/remote/subfolder"
sendfile "readme.txt" /type=ASCII
FTPLOGOFF
EXIT

Open in new window


So... I am not the best person to answer your question with regard to the built-in ftp.exe program but I can give you the basic steps:
1.  Make a text file that contains the same commands you would type into ftp.exe ... I'm no expert but I think it would be something like:
open ftp.linuxmachine.com
MyLogin
MyPassword
lcd c:\local\source\folder
cd /remote/subfolder
ascii
put readme.txt
bye

Open in new window

 There is probably something wrong with that but you can type "?" at the command prompt inside ftp.exe to see a list of commands and then ? <command> to see a brief description of what it does.
2. use the -s command line option when you launch ftp.exe to make it run your command script... you can do "ftp /?" from the windows command prompt to see a list of the command line syntax for ftp.exe... this is different from the "?" help syntax mentioned above that is available while ftp.exe is running.
3. make a scheduled task or batch file that launches ftp.exe with your command line.


... or if you have WinSCP you can script that also and it has the bonus of being able to run some shell commands on the remote host ... so depending on what you needed to run on the linux side it is possible that you could do the entire thing (both sides) from a WinSCP script.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now