itortu
asked on
transfer file via sftp
If possible, I would like an example of how to transfer a file that resides on a windows box, location: c:\\data\myfile.xml to a linux server location: /opt/dev/destinationfolder / via sftp.
If I need to add more information needed for this script, please let me know.
thank you very much.
If I need to add more information needed for this script, please let me know.
thank you very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
jmatix,
what else do i need to do on putty so it is configured and running always?
is there a chance that you can show me where in the script i add the line?
thank you.
what else do i need to do on putty so it is configured and running always?
is there a chance that you can show me where in the script i add the line?
thank you.
ASKER
for these strings:
`pscp -pw <password> c:\\data\\myfile.xml user\@server:/opt/dev/dest inationfol der/`;
system('pscp -pw <password> c:/data/myfile.xml user@server:/opt/dev/desti nationfold er/');
do i have to replace the word server with the actual server name? how do i include the port, is it necessary to include the port?
`pscp -pw <password> c:\\data\\myfile.xml user\@server:/opt/dev/dest
system('pscp -pw <password> c:/data/myfile.xml user@server:/opt/dev/desti
do i have to replace the word server with the actual server name? how do i include the port, is it necessary to include the port?
To prevent hardcoding your password in the script you can use public/private keys authentication using Pagent. You can generate those keys using PuTTYgen. Remember to encrypt the private key with a password. Copy the public key into a file named known_hosts under .ssh directory in your home directory on the Linux server. Load the private key into Pagent. Make Pagent to run on Windows startup.
Create and configure a connection to the server in Putty and name it say 'myconn'. Make sure you select 'Agent Forwarding' for authentication. Then add this line after you create the XML file:
$root->printToFile ("C:\\Temp\\data.xml");
`C:\\<Path to Putty>\\pscp c:\\data\\myfile.xml myconn:/opt/dev/destinatio nfolder/`;
For more info on configuring Putty see the documentation at:
http://www.chiark.greenend.org.uk/~sgtatham/putty/faq.html
http://www.chiark.greenend.org.uk/~sgtatham/putty/docs.html
Create and configure a connection to the server in Putty and name it say 'myconn'. Make sure you select 'Agent Forwarding' for authentication. Then add this line after you create the XML file:
$root->printToFile ("C:\\Temp\\data.xml");
`C:\\<Path to Putty>\\pscp c:\\data\\myfile.xml myconn:/opt/dev/destinatio
For more info on configuring Putty see the documentation at:
http://www.chiark.greenend.org.uk/~sgtatham/putty/faq.html
http://www.chiark.greenend.org.uk/~sgtatham/putty/docs.html
In the first method replace 'server' with your actual server name or ip address. No need to give port if default - ie. 22 for pscp. The second method I gave above is more preferable.
ASKER
before i get into the use of public/ private keys, let me try it with a user and password specified just to test.
please let me know if this is how the string should look:
`C:\\<Program Files\PuTTY\putty.exe>\\ps cp -pw <password> c:\\data.xml user\@myconn:/opt/dev/dest inationfol der/`;
i did create the connection in the putty configuration.
where in the configuration interface I make Pagent to run on Windows start up?
I wait for you to confirm whether the string looks correct or not.
Thank you.
10-20-2010-10-56-16-AM.png
please let me know if this is how the string should look:
`C:\\<Program Files\PuTTY\putty.exe>\\ps
i did create the connection in the putty configuration.
where in the configuration interface I make Pagent to run on Windows start up?
I wait for you to confirm whether the string looks correct or not.
Thank you.
10-20-2010-10-56-16-AM.png
ASKER
when i run the script it tell me unrecognized character \P passed
line 67:
`C:\\<Program Files\PuTTY\putty.exe>\\ps cp -pw <password> c:\\data.xml user\@myconn:/opt/dev/apac he-2.2.11/ htdocs/wtx ml/`;
line 67:
`C:\\<Program Files\PuTTY\putty.exe>\\ps
`"C:\\Program Files\\PuTTY\\pscp.exe" -pw <password> c:\\data.xml <user>\@myconn:/opt/dev/de stinationf older/`;
Replace <password> with your password and <user> with your user id.
In the Connection > SSH > Auth tab make sure you checked 'Attempt authentication using Pageant'. Also check 'Allow agent forwarding'
To start Pageant on Windows startup, create a shortcut to Pageant in your Windows > Start menu > Startup folder.
Replace <password> with your password and <user> with your user id.
In the Connection > SSH > Auth tab make sure you checked 'Attempt authentication using Pageant'. Also check 'Allow agent forwarding'
To start Pageant on Windows startup, create a shortcut to Pageant in your Windows > Start menu > Startup folder.
ASKER
it is not copying the file. i even tried to move it to a directory of my local apache installation.
`"C:\\Program Files\\PuTTY\\pscp.exe" c:\\data.xml \@localhost:81/wtxml/`;
`"C:\\Program Files\\PuTTY\\pscp.exe" c:\\data.xml \@localhost:81/wtxml/`;
ASKER
i also added a new connection on putty to my localhost on port 81 so:
`"C:\\Program Files\\PuTTY\\pscp.exe" c:\\data.xml \@localhost:81/wtxml/`;
would look like:
`"C:\\Program Files\\PuTTY\\pscp.exe" c:\\data.xml \@local:/wtxml/`;
and made sure that:
In the Connection > SSH > Auth tab make sure you checked 'Attempt authentication using Pageant'. Also check 'Allow agent forwarding'
`"C:\\Program Files\\PuTTY\\pscp.exe" c:\\data.xml \@localhost:81/wtxml/`;
would look like:
`"C:\\Program Files\\PuTTY\\pscp.exe" c:\\data.xml \@local:/wtxml/`;
and made sure that:
In the Connection > SSH > Auth tab make sure you checked 'Attempt authentication using Pageant'. Also check 'Allow agent forwarding'
Check if the server has SSH server running on it.
ASKER
none all the processes for my user on that linux server have ssh in their names.
root has ssh, but i do not lob on to the server as root.
what would be the next step?
thank you.
root has ssh, but i do not lob on to the server as root.
what would be the next step?
thank you.
ASKER
the linux person also informed me that we have just an ssh client.
You cannot use ssh/scp to copy file to a server if the server does not have ssh server running. You should get the ssh server running on the server. If FTP server is running on the server and you can live with the reduced security of FTP then you can also use FTP to transfer the file.
Another option is to map the Linux server directory as a drive on your Windows PC using something like Samba.
Another option is to map the Linux server directory as a drive on your Windows PC using something like Samba.
ASKER
there are some things that i do not understand very clearly. one is that why if the server does not have ssh, then, the protocol used to connect via filezilla is ftp?
Yes, FileZilla uses FTP.
ASKER
could you help me try this using just ftp I think i can live with the reduced security for now.
thank you much.
thank you much.
ASKER
i followed the steps on previous comment.
user
<testuser>
<coyut>
cd /opt/dev/wtxml/
put C:\wtxml\data.xml
quit
then on command window:
10-20-2010-1-04-01-PM.png
user
<testuser>
<coyut>
cd /opt/dev/wtxml/
put C:\wtxml\data.xml
quit
then on command window:
10-20-2010-1-04-01-PM.png
ASKER
can the file be transfer via http?
the windows server where the file is located would be
http://webtrend1:7099/xmlsource/
to destination
http://contrib-dev.energy.com:8081/wtxml
the windows server where the file is located would be
http://webtrend1:7099/xmlsource/
to destination
http://contrib-dev.energy.com:8081/wtxml
FTP failed because of these facts:
1. It could not connect to contrib-dev.alliant-energy .com. Check if the server name is spelled correct.
2. userid and password should be given without angle brackets (<>)
user
testuser
coyut
cd /opt/dev/wtxml/
put C:\wtxml\data.xml
quit
1. It could not connect to contrib-dev.alliant-energy
2. userid and password should be given without angle brackets (<>)
user
testuser
coyut
cd /opt/dev/wtxml/
put C:\wtxml\data.xml
quit
ASKER
the server name is spelled correctly, but to access it needs port 8081
FTP server usually listens on port 21. Make sure FTP server is running on contrib-dev.alliant-energy .com.
For http transfer: Do you have WebDAV on the server? You can check by adding it as a network place in your windows explorer.
Right click on 'My Network Places' in explorer and select 'Open'
Click 'Add a network place'
Next
Choose another network location
Enter http://contrib-dev.energy.com:8081
Enter username and password
For http transfer: Do you have WebDAV on the server? You can check by adding it as a network place in your windows explorer.
Right click on 'My Network Places' in explorer and select 'Open'
Click 'Add a network place'
Next
Choose another network location
Enter http://contrib-dev.energy.com:8081
Enter username and password
ASKER
So far I was able to copy the file by creating a shell script:
#!/bin/sh
URL=http://webtrend1/wtxml/data.xml
OUT=/opt/contrib-dev/apach e/htdocs/w txml/data. xml
http_proxy=http://proxy.com
WGET="wget --no-cache --quiet"
$WGET -O $OUT $URL
if [ $? -ne 0 ]; then
echo 1>&2 Unable to retrieve file $URL
exit $?
fi
#!/bin/sh
URL=http://webtrend1/wtxml/data.xml
OUT=/opt/contrib-dev/apach
http_proxy=http://proxy.com
WGET="wget --no-cache --quiet"
$WGET -O $OUT $URL
if [ $? -ne 0 ]; then
echo 1>&2 Unable to retrieve file $URL
exit $?
fi
ASKER
i added the hostname and the port, but will i have to always do the log in? or when running it automatically, it will use the credentials passed on the string?