Solved

test script and upload file to ftp from Linux command line

Posted on 2013-11-25
3
842 Views
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."
0
Comment
Question by:Delta7428
  • 2
3 Comments
 
LVL 16

Expert Comment

by:AlexPace
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.
0
 

Author Comment

by:Delta7428
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.
0
 
LVL 16

Accepted Solution

by:
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 "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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We all have limited time to study long and complicated information about RAID theories, but you may be interested as to how RAID 5 works. We made it simple for you by providing the shortest and easiest explanation ever.   First we need to remind …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now