Copy file to remote server with username and pasword?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
izy
Posts: 43
Joined: 29 May 2012 13:29

Copy file to remote server with username and pasword?

#1 Post by izy » 06 Nov 2012 06:22

Instead to copyfiles in my local directory(pushd "c:\LASTNO\FTP\prenos\") I want to put them on server:
Here is server details:

set dest_server_name=192.xxx.xx.xx
set dest_username=lalala
set dest_password=123456
set dest_directory=/spark_data/RangerData/

Please write me in my code below how to do that?

----------------------------------------
Code:

@echo off
pushd "c:\LASTNO\FTP\prenos\"

set "db=file_database_DO_NOT_DELETE.txt"

if not exist "%db%" type nul>"%db%"

del list.ftp 2>nul
del list2.ftp 2>nul
del filelist.txt 2>nul
del filelist2.txt 2>nul

set server_name=v-sss-xxx
set username=racauser
set password=racapass

set remote_directory=raca/OTHERS/out
set filespec=GL_*.txt
for /f "delims=" %%a in ("%filespec%") do set filetype=%%~xa


echo ---------------------------------------------------------------------------
echo %date% %time% Begin Transfer

(
echo open %server_name%
echo %username%
echo %password%
echo cd %remote_directory%
echo ls %filespec%
echo quit
)>list.ftp

FTP -s:list.ftp >filelist.txt

for /f "delims=" %%a in (
'type "filelist.txt"^|find /i "%filetype%"^|find /i /v "ftp>"'
) do cmd /c >> filelist2.txt echo %%a

move /y filelist2.txt filelist.txt >nul


for /f "delims=" %%a in ('type "filelist.txt"') do (
find /i "%%a"<"%db%" >nul || >>filelist2.txt echo %%a
)

(
echo open %server_name%
echo %username%
echo %password%
echo binary
echo cd %remote_directory%
)>list2.ftp


for /f "delims=" %%a in ('type "filelist2.txt"') do (
>>list2.ftp echo mget %%a
>>list2.ftp echo y
>>"%db%" echo %%a
)

echo quit>>list2.ftp

FTP -s:list2.ftp

del list.ftp 2>nul
del list2.ftp 2>nul
del filelist.txt 2>nul
del filelist2.txt 2>nul

echo %date% %time% Done FTP Transfer
echo.
echo.
popd

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Copy file to remote server with username and pasword?

#2 Post by abc0502 » 06 Nov 2012 06:36

I don't understand much about FTP but you can download the files then re-upload to the new one then delete files from your pc.

I don't know if the ftp can handle file transfer between servers :?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy file to remote server with username and pasword?

#3 Post by foxidrive » 06 Nov 2012 06:40

Try this: replace this:

Code: Select all

@echo off
pushd "c:\LASTNO\FTP\prenos\"


with this:

Code: Select all

@echo off
NET USE Z:  \\192.168.1.1\spark_data\RangerData 123456  /USER:lalala
cd /d z:\



and replace the last line

popd

with this

net use z: /delete

izy
Posts: 43
Joined: 29 May 2012 13:29

Re: Copy file to remote server with username and pasword?

#4 Post by izy » 06 Nov 2012 08:20

With net use I cannot login to server. I receive error: The network connection could not be found.

I CAN login use this:
ftp://username:passwords@192.168.1.1/

and 192.168.1.1 is Windows Server.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy file to remote server with username and pasword?

#5 Post by foxidrive » 06 Nov 2012 09:01

izy wrote:With net use I cannot login to server. I receive error: The network connection could not be found.


Is the server online? The error message would seem to indicate that the IP address you used is not the right one.

I CAN login use this:
ftp://username:passwords@192.168.1.1/
and 192.168.1.1 is Windows Server.


That is of no use, unless you want to FTP everything to another FTP server.
An FTP server cannot keep a database of all the files transferred that is in the batch file.

izy
Posts: 43
Joined: 29 May 2012 13:29

Re: Copy file to remote server with username and pasword?

#6 Post by izy » 06 Nov 2012 12:31

I just want to copy files instead to the local disk, copy files to another windows server. Server is online, but i put fake IP 192.168.1.1 because of security.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy file to remote server with username and pasword?

#7 Post by foxidrive » 06 Nov 2012 21:51

I don't know what IP you put in but your error message shows that there is no server there.


Type this and tell me what happens. Use the correct IP address - and 192.168.x.x is not a security risk as it is behind a router.

net use z: \\192.168.1.1\spark_data\RangerData

izy
Posts: 43
Joined: 29 May 2012 13:29

Re: Copy file to remote server with username and pasword?

#8 Post by izy » 07 Nov 2012 01:42

I receive error:

System error 53 has occurred.
The network path was not found.

The system cannot find the drive specified.

I try with this:

net use z: \\192.168.1.1\spark_data\RangerData
cd /d z:\

...

net use z: /delete

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy file to remote server with username and pasword?

#9 Post by foxidrive » 07 Nov 2012 03:08

http://answers.yahoo.com/question/index ... 115AA2Z370

This is not a batch file issue, izy, you will have to see your admin.

izy
Posts: 43
Joined: 29 May 2012 13:29

Re: Copy file to remote server with username and pasword?

#10 Post by izy » 07 Nov 2012 03:45

But can I use "net use -> cd /d z:\" if is it on other site windows server?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy file to remote server with username and pasword?

#11 Post by foxidrive » 07 Nov 2012 03:50

NET USE can map a server to a local drive letter.

Then if it is mapped to z: you can use

cd /d z:\

izy
Posts: 43
Joined: 29 May 2012 13:29

Re: Copy file to remote server with username and pasword?

#12 Post by izy » 07 Nov 2012 04:20

But what if I couldn't "create" mapped disk like z: ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy file to remote server with username and pasword?

#13 Post by foxidrive » 07 Nov 2012 05:38

If you can't access the server then you cannot transfer files to it.

We can't tell what you have done and can only judge on the error reports that you tell us.
For some reason you can't log into the server - maybe your Admin have locked it down.

izy
Posts: 43
Joined: 29 May 2012 13:29

Re: Copy file to remote server with username and pasword?

#14 Post by izy » 07 Nov 2012 05:51

Is it any other way instead of net use, like pushd to copy files to remote server?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy file to remote server with username and pasword?

#15 Post by foxidrive » 07 Nov 2012 06:09

You can use pushd with a UNC path too, but as far as I know not with user and password.

Post Reply