Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


test script and upload file to ftp from Linux command line

Posted on 2013-11-25
Medium Priority
Last Modified: 2013-11-26
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."
Question by:Delta7428
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 16

Expert Comment

ID: 39675658
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.

Author Comment

ID: 39677518
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.
LVL 16

Accepted Solution

AlexPace earned 2000 total points
ID: 39678000
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 "" /user=MyLogin /pw=MySecret 
FTPCD "/remote/subfolder"
sendfile "readme.txt" /type=ASCII

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:
lcd c:\local\source\folder
cd /remote/subfolder
put readme.txt

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.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lets start to have a small explanation what is VAAI(vStorage API for Array Integration ) and what are the benefits using it. VAAI is an API framework in VMware that enable some Storage tasks. It first presented in ESXi 4.1, but only after 5.x sup…
The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question