Send files from LAMP stack to Windows SFTP server via PHP?

If all you want to do is send one file, curl works, I suppose, but if you want to do anything more - like maybe verifying that the file has been uploaded, upload multiple files, use publickey authentication, or whatever, curl just isn't versatile enough for that.

Up vote 1 down vote favorite share g+ share fb share tw.

I'm having a good deal of trouble sending a file from a linux server to a windows server over SFTP via PHP. I seem to be connecting just fine, but it always throws an error that I can't create the file on the remote server's end. It's possible that I am messing up at the syntax for the file location.

I have tried two ways now, one using ssh2_scp_send(), and another trying fopen(ssh2. Sftp://D:/path/file. Csv) Also, logging into the sftp server via a client puts me at my home folder (ie D:\path\to\home) but if I do a ssh2_exec($connection, 'cd'); and print the stream to the screen, it shows me that my ssh session is currently in the windows filesystem on the C drive.

I was hoping someone would have some advice on this. And I'm not married to this method. I'm using php on my end because it's all coming from a drupal module, but I could always try and incorporate another method.

Php ssh lamp sftp link|improve this question edited Dec 8 '10 at 17:52Mark Trapp7,24821025 asked Dec 8 '10 at 17:24Jay232.

It has the ability to send via SFTP. – Darren Dec 8 '10 at 18:29 I haven't yet, but that's my next plan. I'm just hoping that I'm getting the path correct for the remote windows server.

Im not familiar with formatting it for windows, and if I need to include the drive in the path, etc. – Jay Dec 8 '10 at 18:49.

If all you want to do is send one file, curl works, I suppose, but if you want to do anything more - like maybe verifying that the file has been uploaded, upload multiple files, use publickey authentication, or whatever, curl just isn't versatile enough for that. My recommendation would be to use phpseclib, a pure PHP SFTP implementation.

CURL can use th sftp library. $localfile = 'test. Txt'; $ch = curl_init(); $fp = fopen ($localfile, "r") or die('Cannot open textfile'); curl_setopt($ch, CURLOPT_URL,"sftp://123.123.123.123:10022/username/test.

Txt"); curl_setopt($ch, CURLOPT_USERPWD, "username:password"); curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); if(curl_exec($ch)){ echo 'File was successfully transferred using SFTP'; }else{ echo 'File was unable to be transferred using SFTP'; } curl_close ($ch).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions