Я хочу скопировать файл от клиента на удаленный сервер, но я не понимаю, как сделать это с помощью API SFTP Libssh Library. Клиент на сервере с простой функцией, такой как sftp_transfer (sourcefile (например, c: \ my document \ hello world.txt), remotefile (/home/user/hello world.txt), справа (чтение и написание)) ? Код: < /p>
file = sftp_open(sftp, "/home/helloworld.txt",access_type,1);
< /code>
После этого файл создается на сервере, а затем он записывает в этот созданный файл с буфером: < /p>
const char *helloworld = "Hello, World!\n";
int length = strlen(helloworld);
nwritten = sftp_write(file, helloworld, length);
Мой вопрос теперь заключается в том, если у меня есть файл, например, файл .doc, и я хочу перенести/загрузить этот файл из C: \ mydocument \ document.doc , чтобы удалить удаленный сервер/home/user/document.doc , как я могу сделать это с этим методом? sftp_write () Функция отправки его как Helloworld в образце функции?// Set variable for the communication
char buffer[256];
unsigned int nbytes;
//create a file to send by SFTP
int access_type = O_WRONLY | O_CREAT | O_TRUNC;
const char *helloworld = "Hello, World!\n";
int length = strlen(helloworld);
//Open a SFTP session
sftp = sftp_new(my_ssh_session);
if (sftp == NULL)
{
fprintf(stderr, "Error allocating SFTP session: %s\n",
ssh_get_error(my_ssh_session));
return SSH_ERROR;
}
// Initialize the SFTP session
rc = sftp_init(sftp);
if (rc != SSH_OK)
{
fprintf(stderr, "Error initializing SFTP session: %s.\n",
sftp_get_error(sftp));
sftp_free(sftp);
return rc;
}
//Open the file into the remote side
file = sftp_open(sftp, "/home/helloworld.txt",access_type,1);
if (file == NULL)
{
fprintf(stderr, "Can't open file for writing: %s\n",ssh_get_error(my_ssh_session));
return SSH_ERROR;
}
//Write the file created with what's into the buffer
nwritten = sftp_write(file, helloworld, length);
if (nwritten != length)
{
fprintf(stderr, "Can't write data to file: %s\n",
ssh_get_error(my_ssh_session));
sftp_close(file);
return SSH_ERROR;
}
Подробнее здесь: https://stackoverflow.com/questions/136 ... h-and-sftp
Как скопировать файл в C/C ++ с помощью Libssh и SFTP ⇐ C++
Программы на C++. Форум разработчиков
-
Anonymous
1751258276
Anonymous
Я хочу скопировать файл от клиента на удаленный сервер, но я не понимаю, как сделать это с помощью API SFTP Libssh Library. Клиент на сервере с простой функцией, такой как [b] sftp_transfer (sourcefile (например, c: \ my document \ hello world.txt), remotefile (/home/user/hello world.txt), справа (чтение и написание)) [/b]? Код: < /p>
file = sftp_open(sftp, "/home/helloworld.txt",access_type,1);
< /code>
После этого файл создается на сервере, а затем он записывает в этот созданный файл с буфером: < /p>
const char *helloworld = "Hello, World!\n";
int length = strlen(helloworld);
nwritten = sftp_write(file, helloworld, length);
Мой вопрос теперь заключается в том, если у меня есть файл, например, файл .doc, и я хочу перенести/загрузить этот файл из C: \ mydocument \ document.doc , чтобы удалить удаленный сервер/home/user/document.doc , как я могу сделать это с этим методом? sftp_write () Функция отправки его как Helloworld в образце функции?// Set variable for the communication
char buffer[256];
unsigned int nbytes;
//create a file to send by SFTP
int access_type = O_WRONLY | O_CREAT | O_TRUNC;
const char *helloworld = "Hello, World!\n";
int length = strlen(helloworld);
//Open a SFTP session
sftp = sftp_new(my_ssh_session);
if (sftp == NULL)
{
fprintf(stderr, "Error allocating SFTP session: %s\n",
ssh_get_error(my_ssh_session));
return SSH_ERROR;
}
// Initialize the SFTP session
rc = sftp_init(sftp);
if (rc != SSH_OK)
{
fprintf(stderr, "Error initializing SFTP session: %s.\n",
sftp_get_error(sftp));
sftp_free(sftp);
return rc;
}
//Open the file into the remote side
file = sftp_open(sftp, "/home/helloworld.txt",access_type,1);
if (file == NULL)
{
fprintf(stderr, "Can't open file for writing: %s\n",ssh_get_error(my_ssh_session));
return SSH_ERROR;
}
//Write the file created with what's into the buffer
nwritten = sftp_write(file, helloworld, length);
if (nwritten != length)
{
fprintf(stderr, "Can't write data to file: %s\n",
ssh_get_error(my_ssh_session));
sftp_close(file);
return SSH_ERROR;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/13691520/how-to-copy-a-file-in-c-c-with-libssh-and-sftp[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия