2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FTPサーバにファイルを転送する

Posted at

概要

PHPでFTPサーバにファイルを転送する基本をまとめておく。

基本サンプル

<?php

$ftpServer   = 'XXXXX.com'; 
$ftpUserName = 'XXXXX';
$ftpUserPass = 'XXXXX';

$localFile  = '/Users/Test/test.txt'; //転送したいファイルを書く
$remoteFile = '/home/XXXXX/Test/test.txt'; //転送先での名前を指定する

// 接続を確立する
$conId = ftp_connect($ftpServer);

// ユーザー名とパスワードでログインする
$loginResult = ftp_login($conId, $ftpUserName, $ftpUserPass);

// ファイルをアップロードする
if (ftp_put($conId, $remoteFile, $localFile, FTP_ASCII)) {
 echo "successfully uploaded $localFile\n";
} else {
 echo "There was a problem while uploading $localFile\n";
}

// 接続を閉じる
ftp_close($conId);
?>
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?