2011-06-01 21:15:14 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/netutils/ftpc/ftpc_rename.c
|
|
|
|
*
|
2021-06-11 06:22:42 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2011-06-01 21:15:14 +02:00
|
|
|
*
|
2021-06-11 06:22:42 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-06-01 21:15:14 +02:00
|
|
|
*
|
2021-06-11 06:22:42 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2011-06-01 21:15:14 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-06-03 01:45:31 +02:00
|
|
|
#include "ftpc_config.h"
|
2011-06-01 21:15:14 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-07-11 18:11:18 +02:00
|
|
|
#include "netutils/ftpc.h"
|
2011-06-01 21:15:14 +02:00
|
|
|
|
|
|
|
#include "ftpc_internal.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ftpc_rename
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Rename a file on the remote server.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-12-13 16:35:40 +01:00
|
|
|
int ftpc_rename(SESSION handle, FAR const char *oldname,
|
|
|
|
FAR const char *newname)
|
2011-06-01 21:15:14 +02:00
|
|
|
{
|
|
|
|
FAR struct ftpc_session_s *session = (FAR struct ftpc_session_s *)handle;
|
|
|
|
char *oldcopy;
|
|
|
|
char *newcopy;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
oldcopy = strdup(oldname);
|
2020-12-13 16:35:13 +01:00
|
|
|
if (!oldcopy)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2011-06-01 21:15:14 +02:00
|
|
|
ftpc_stripslash(oldcopy);
|
2011-06-02 03:14:12 +02:00
|
|
|
|
|
|
|
/* A RNFR request asks the server to begin renaming a file. A typical
|
|
|
|
* server accepts RNFR with:
|
|
|
|
*
|
|
|
|
* - "350 Requested file action pending further information" if the file
|
|
|
|
* exists
|
|
|
|
*
|
|
|
|
* Or rejects RNFR with:
|
|
|
|
*
|
|
|
|
* - "450 Requested file action not taken"
|
|
|
|
* - "550 Requested action not taken"
|
|
|
|
*/
|
|
|
|
|
2011-06-01 21:15:14 +02:00
|
|
|
ret = ftpc_cmd(session, "RNFR %s", oldcopy);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
free(oldcopy);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2020-12-13 16:35:13 +01:00
|
|
|
free(oldcopy);
|
2011-06-01 21:15:14 +02:00
|
|
|
newcopy = strdup(newname);
|
2020-12-13 16:35:13 +01:00
|
|
|
if (!newcopy)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2011-06-01 21:15:14 +02:00
|
|
|
ftpc_stripslash(newcopy);
|
2014-04-14 00:24:28 +02:00
|
|
|
|
2011-06-02 03:14:12 +02:00
|
|
|
/* A RNTO request asks the server to finish renaming a file. RNTO must
|
|
|
|
* come immediately after RNFR; otherwise the server may reject RNTO with:
|
|
|
|
*
|
|
|
|
* - "503 Bad sequence of commands"
|
|
|
|
*
|
|
|
|
* A typical server accepts RNTO with:
|
|
|
|
*
|
|
|
|
* - "250 Requested file action okay, completed" if the file was renamed
|
|
|
|
* successfully
|
|
|
|
*
|
|
|
|
* Or rejects RMD with:
|
|
|
|
*
|
|
|
|
* - "550 Requested action not taken"
|
|
|
|
* - "553 Requested action not taken"
|
|
|
|
*/
|
|
|
|
|
2011-06-01 21:15:14 +02:00
|
|
|
ret = ftpc_cmd(session, "RNTO %s", newcopy);
|
|
|
|
|
|
|
|
free(newcopy);
|
|
|
|
return ret;
|
|
|
|
}
|