Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP Batch file 2

Status
Not open for further replies.

jackps

Technical User
Jul 7, 2003
66
0
0
HK
Dear all
Not sure if this is the right forum for message, but it is related to win2k, so i give a try on this forum. Sorry for causing any inconvenience.
I want to make a batch file which will automatically connect to remote server and upload the specific files to it.
can someone please show me a simple example on how to connect to remote server providing username and password.

Thx alot

Jack
 
There are several ways. One is just to Pipe the commands from a text file into the FTP program.

However ist not very flexible and does not recover well form errors. You are also never 100% certain that the file was sent.

I would prefer using a scripting language like Perl to program the FTP process.
 
ftp -n -s:filename.txt

Within filename.txt, put the following:

open hostname
user username
password
ftp commands
quit

----------
Example

ftp -n -s:putlogfiles.txt

Contents of putlogfiles.txt:
open ftp.abc.com
user joeuser
mypassword
lcd c:\temp
put file1.log
put file2.log
quit


Hope that helps....
 
I am trying to accomplish basically the same thing. I have this script working by now i am having a problem with the length of the directory in the cd command. Here is the script i am trying to run:

open lrs035r1.rr1.stilt.mo.us
tboston
tb0716
prompt
type binary
cd \\cdbas400\lotus\domino\spfld1\domino\html\forms\download
lcd q:\webpost\forms
put test1.txt
quit


the error message that i get is that the "specified object is too long, limit is 10 characters". I looked this up and found that i have to put the ~1 in the part of the directory that is over 10 characters but when i do that i get the same error message.

Any suggestions?
 
tboston,
Try taking out the \\ in front of cdbas400. Also you might want to change your password since you posted it. Hope it works for you
 
Is there any way to write this to include a connectivity check before ftp transfer? I , too, am pushing files from one system to another, but as it will run as a scheduled task (.bat), I need to ensure that the users who transmit to me have connectivity established before the the batch file runs. Any help is greatly appreciated. Thanks.

Captain_D
"Taking Care of America's Sons and Daughters"
 
Hyperiest

Here's a batch file that is used to copy files between our servers. Hope it helps?

rem @echo off

rem **** Method - Check for transfer file at sending site, if found delete**
rem **** previous months Stats transfer file on REMOTE server. Move this **
rem **** months file from sending site to REMOTE server and updates log **
rem **** file on shared folders on both REMOTE & sending server **
rem **** Transfer Account needs access Permissions at each end **
rem ************************************************************************

REM **** CHECKS FOR NEW FILE TO SEND ****
if exist e:\data\export\transfer\database.mdb goto :start
goto :end

:start
REM **** MAPS DRIVE TO REMOTE SERVER AND CHECKS FOR PREVIOUSLY ****
REM **** SENT FILE (\\REMOTESERVER\data\stats) ****
net use g: \\10.10.10.10\data PASSWORD /user:"DOMAIN\USERNAME"
if exist g:\stats\database.mdb goto :remove
goto :copy

:remove
REM **** REMOVES PREVIOUSLY SENT FILE FROM REMOTE SERVER PRIOR TO ****
REM **** STARTING TRANSFER OF NEW FILE (\\REMOTESERVER\data\stats) ****
del g:\stats\database.mdb
goto :copy

:copy
REM **** Moves/copies FILE FROM SENDING SERVER (\\SOURCESERVER\data\export) ****
REM **** TO REMOTE SERVER (\REMOTESERVER\data\stats) ****
REM move e:\data\export\transfer\database.mdb g:\stats\database.mdb
copy e:\data\export\transfer\database.mdb g:\stats\database.mdb
REM **** CHECK TO ENSURE DELIVERY TO REMOTE SERVER ****
if not exist g:\stats\database.mdb goto :error
net use t: \\10.10.10.10\logshare
dir g:\stats\*e.mdb > t:\transfer\StatsTransfer.log
REM **** CLOSES MAPPED DRIVES TO REMOTE SERVER ***
net use t: /delete
net use g: /delete
REM *** TRANSFER COMPLETED ***
goto :del

:del
REM **** UPDATES LOG ON SENDING SITE****
echo "Your Monthly Stats Transfer completed Successfully" >d:\logshare\transfer\StatsTransfer.log
del e:\data\export\transfer\database.mdb
REM *** DIRECTORY CLEARED ON SENDING SITE ***
goto :end

REM **** UPDATES LOG ON SENDING SITE & CLOSES MAPPED DRIVE ****
:error
echo "Your Monthly Stats Transfer Failed to complete" > e:\logshare\transfer\StatsTransfer.log
net use g: /delete
goto :end

:end


 
Thanks, Airshot. I will take this and see if I can mod it for secure ftp, since all my clients are remote systems on different domain servers on different domains. I think this is do-able, but my chief programmer at work tells me he needs me to buy Microsoft Visual Studio.NET Full version w/subscription ($2400!) in order to write the script. Thanks for the tip. I will let you know if it works.

Captain_D
"Taking Care of America's Sons and Daughters"
 
Nope, didn't work. The code you gave still did not check for connectivity prior to beginning the data transfer. Not only that, but since the systems reside on multiple different domains, mapping a drive is not possible. I think I will end up using a custom configurable ftp upload setup, perhaps with ABC UpLoad FTP, to put the user back into the equation. I really did not want to have to do this, but it would be nice to put some of the onus back on the user to ensure they do their jobs. When I finish the script with VisualStudio.NET, I will post it or send it to you. Thanks again.

Captain_D
"Taking Care of America's Sons and Daughters"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top