2012-03-20 2 views
0
<?php 
    $localfile = 'test1.txt'; 
    $fp = fopen ($localfile, "r") or die('Cannot open textfile'); 
    $connection = ssh2_connect('sftp_server_path/folder',22); 
    ssh2_auth_password($connection, 'username', 'password'); 

    $sftp = ssh2_sftp($connection) or die ("Cannot connect to server"); 


    $ch = curl_init(); 
    curl_setopt($ch,  CURLOPT_URL,"sftp_server_path/folder/test1.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'; 
    } 

?> 

위의 코드를 연결하여 sftp 서버로 전송하면이 코드가 실행되어 "파일이 SFTP를 사용하여 성공적으로 전송되었습니다"라는 메시지가 나타납니다. 하지만 sftp 서버에서 폴더 구조를 볼 때 sftp 서버에서 전송 파일을 볼 수 없습니다. 정확히 내가 뭘해야되는거야?어떻게 SFTP 서버에서 파일에 액세스 할 수 있습니까?

+0

즉, myfolder 권한을 의미합니까? 그것의 777. – user1122910

답변

1

는 다음과 같은 시도 :

$sftp = ssh2_connect('shell.example.com', 22); 
ssh2_auth_password($sftp, 'username', 'password'); 

ssh2_scp_send($sftp, '/local/filename', '/remote/filename', 0644); 

http://sg2.php.net/manual/en/function.ssh2-scp-send.php

+0

ssh2_scp_send ($ connection, 'test1.txt', 'foldername/test1.txt', 777); 이 코드를 사용했습니다. 하지만 브라우저가로드 중입니다 ........... – user1122910

+0

미안 해요 'ssh2_scp_send ($ sftp,'$ 연결 대신 –

+0

:) 완료 했어야했습니다. :) – user1122910

0

이식성, 내가 phpseclib, a pure PHP SFTP implementation를 사용하는 것이 좋습니다 것입니다. PECL SSH2와 같은 비표준 확장을 사용하는 다른 서버로 옮기고 싶다면 phpseclib가 플러그 앤 플레이를 사용하는 반면, 그렇게하는 것이 더 어렵습니다.

관련 문제