test script and upload file to ftp from Linux command line

Posted on 2013-11-25
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 500 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
Concerto Cloud Services, a provider of fully managed private, public and hybrid cloud solutions, announced today it was named to the 20 Coolest Cloud Infrastructure Vendors Of The 2017 Cloud  (…
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …
This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…

739 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