FTP file creation

Author Topic: FTP file creation  (Read 8951 times)

Offline WalalayoTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 3
  • Posts: 180
  • Karma: 2
    • JavaScript Editor
FTP file creation
« on: 09-20-2011, 03:33:02 »
Hi
I need to create a file on the server using ftp via a PHP script.I can make a directory and connect etc ok, but I don't know how to create a file and put contents in etc. Thanks very much


Offline portodon

  • Trade Count: (0)
  • Newbie
  • *
  • Thank You 0
  • Posts: 1
  • Karma: 0
  • Gender: Female
    • Pozycjonowanie Szczecin
Re: FTP file creation
« Reply #1 on: 02-28-2017, 08:10:13 »
Code:
Only registered users can see contents. Please click here to Register or Login.
newbielink:http://www.marketing.szczecin.pl [nonactive]


Offline Lishmalinyjames

  • Trade Count: (0)
  • Hero Member
  • *****
  • Thank You 3
  • Posts: 797
  • Karma: 0
    • Oneplus Service Center in Chennai
Re: FTP file creation
« Reply #2 on: 05-28-2021, 10:52:18 »
Open Control Panel.
Click on System and Security.
Click on Administrative Tools.
Double-click the Internet Information Services (IIS) Manager shortcut.
On the "Connections" pane, right-click Sites, and select the Add FTP Site option.

Offline saravanan28

  • Trade Count: (0)
  • Sr. Member
  • ****
  • Thank You 2
  • Posts: 428
  • Karma: 0
Re: FTP file creation
« Reply #3 on: 06-07-2021, 09:13:01 »
View the 'FTP overview' article to log into your server using an FTP client.
Make sure your client is configured to show hidden files.
Once you're logged in, make sure you're in the correct directory to create the file. ...
Right click and choose 'Create new file'.

Offline john2020

  • Trade Count: (0)
  • Newbie
  • *
  • Thank You 0
  • Posts: 5
  • Karma: 0
Re: FTP file creation
« Reply #4 on: 07-20-2023, 03:01:47 »
To create a file on the server using FTP via a PHP script, you can use the `ftp_put` function. Here's an example:

```php
<?php

// Server details
$server = "example.com";
$username = "your_username";
$password = "your_password";

// File details
$remoteFile = "/path/to/file.txt";
$localFile = "/path/to/local/file.txt";

// Create an FTP connection
$conn = ftp_connect($server);
if (!$conn) {
    die("Failed to connect to FTP server.");
}

// Login to the FTP server
if (!ftp_login($conn, $username, $password)) {
    die("FTP login failed.");
}

// Upload a file
if (ftp_put($conn, $remoteFile, $localFile, FTP_ASCII)) {
    echo "File uploaded successfully.";
} else {
    echo "Failed to upload file.";
}

// Close the connection
ftp_close($conn);

?>
```

Make sure to replace "example.com" with your server's hostname, "your_username" and "your_password" with your FTP credentials, and "/path/to/file.txt" and "/path/to/local/file.txt" with the appropriate paths for your file.

This code connects to the FTP server, logs in with the provided credentials, and then uses the `ftp_put` function to upload the local file to the remote server. The `FTP_ASCII` parameter specifies the transfer mode as ASCII; you can change it to `FTP_BINARY` if you need to transfer binary files.

Once you run this script, it will either display "File uploaded successfully" or "Failed to upload file" based on the success of the operation.


 

Related Topics

  Subject / Started by Replies Last post
10 Replies
7022 Views
Last post 09-09-2014, 01:44:58
by Roy Milson
2 Replies
6959 Views
Last post 02-16-2015, 13:31:03
by xerbotdev
1 Replies
5585 Views
Last post 06-25-2016, 02:26:53
by TomClarke
0 Replies
2108 Views
Last post 04-02-2016, 04:57:02
by chinmay.sahoo
2 Replies
3798 Views
Last post 02-21-2017, 05:33:58
by parveen